如何在Python中将N毫秒添加到日期时间 [英] How can I add N milliseconds to a datetime in Python
本文介绍了如何在Python中将N毫秒添加到日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在这样设置日期时间变量:
I'm setting a datetime var as such:
fulldate = datetime.datetime.strptime(date + ' ' + time, "%Y-%m-%d %H:%M:%S.%f")
其中,日期和时间是日期时间的适当性质的字符串。如何将该日期时间增加N毫秒?
where date and time are string of the appropriate nature for datetime. How can I increment this datetime by N milliseconds?
推荐答案
使用 timedelta
要增加500毫秒:
fulldate = datetime.datetime.strptime(date + ' ' + time, "%Y-%m-%d %H:%M:%S.%f")
fulldate = fulldate + datetime.timedelta(milliseconds=500)
您可以使用它来增加分钟,小时,天等。文档:
You can use it to increment minutes, hours, days etc. Documentation:
https://docs.python.org/ 2 / library / datetime.html#timedelta-objects
这篇关于如何在Python中将N毫秒添加到日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文