作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
试图找出 datetime
模块并需要一些帮助。
我有一个看起来像这样的字符串:
00:03:12,200 --> 00:03:14,316
(即时:分:秒,毫秒)并且需要为每个时间戳添加 10 秒。作为输出:
00:03:22,200 --> 00:03:24,316
执行此操作的 Python 代码是什么?
最佳答案
要解析时间,使用strptime
>>> x = '00:03:12,200 --> 00:03:14,316'
>>> x1 = x.split('-->')
>>> x1
['00:03:12,200 ', ' 00:03:14,316']
>>> t1 = datetime.datetime.strptime(x1[0], '%H:%M:%S,%f ')
>>> t1
datetime.datetime(1900, 1, 1, 0, 3, 12, 200000)
使用时间增量
>>> t = datetime.timedelta(seconds=1)
>>> t
datetime.timedelta(0, 1)
>>>
>>> t1 + t
datetime.datetime(1900, 1, 1, 0, 3, 13, 200000)
>>> k = t1 + t
重新转换为字符串
>>> k.strftime('%H:%M:%S,%f ')
'00:03:13,200000 '
关于python - 将时间添加到特定时间戳的 Python 代码是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4363072/
给定一个带有多个 date_time 戳的字符串,我想 提取第一个戳及其前面的文本 候选字符串可以有一个或多个时间戳 后续的 date_time 戳记将被 sep="-" 隔开 后续date_time
是否可以合并从相机拍摄的文本和照片?我想在照片上标记日期和时间,但我在 Google 上找不到任何内容。 最佳答案 使用下面的代码来实现你所需要的。 Bitmap src = Bitm
有没有办法通过 Graph API 戳另一个用户?基于this post ,并使用 Graph Explorer ,我发布到“/USERID/pokes”,我已经授予它(Graph API 应用程序和
我有两个向左浮动的元素。一个是 body 的第一个 child ,另一个是容器的第一个 child ,容器是 body 的第二个 child 。 ...
我是一名优秀的程序员,十分优秀!