Python 以毫秒为单位的时间
Python time with milliseconds
我有以下日期时间:
d1 = 2015-03-21 14:50:54.0
。
在执行 datetime.strptime(d1, "%Y-%m-%d %H:%M:%S")
时,出现 ValueError: unconverted data remains: .0
错误。我怎样才能增加毫秒的时间?如果不可能,那么如何从 d1
?
中删除毫秒
使用%f
获取时间字符串的毫秒部分:
>>> out = datetime.strptime(d1, "%Y-%m-%d %H:%M:%S.%f")
我有以下日期时间:
d1 = 2015-03-21 14:50:54.0
。
在执行 datetime.strptime(d1, "%Y-%m-%d %H:%M:%S")
时,出现 ValueError: unconverted data remains: .0
错误。我怎样才能增加毫秒的时间?如果不可能,那么如何从 d1
?
使用%f
获取时间字符串的毫秒部分:
>>> out = datetime.strptime(d1, "%Y-%m-%d %H:%M:%S.%f")