将Python中的时间戳转换为UNIX时间戳
我需要将将Python中的时间戳转换为UNIX时间戳,python,parsing,datetime,mongodb,Python,Parsing,Datetime,Mongodb,我需要将01/01/2011 01:48:36.157转换为类似的时间戳,我对Pythons日期/时间库相当不熟悉。最简单的方法是什么?是否有等效的strotime功能 考虑到它也会被接受,而不是unix样式的时间戳。Short anwser: from time import time time() # Gives me 1298046251.375916 您可以将其转换为时间戳: >>> d = datetime.strptime("01/01/2011 01:48:36
01/01/2011 01:48:36.157
转换为类似的时间戳,我对Pythons日期/时间库相当不熟悉。最简单的方法是什么?是否有等效的strotime
功能
考虑到它也会被接受,而不是unix样式的时间戳。Short anwser:
from time import time
time() # Gives me 1298046251.375916
您可以将其转换为时间戳:
>>> d = datetime.strptime("01/01/2011 01:48:36.157", "%m/%d/%Y %H:%M:%S.%f")
我只是坐在
datetime
页面的底部,完成了公式的计算。谢谢感谢我的守护天使为我添加了完整的解析:-)
>>> d = datetime.strptime("01/01/2011 01:48:36.157", "%m/%d/%Y %H:%M:%S.%f")
import time
time.mktime(d.timetuple())