获得当前时间的N天前的时间
import time
import datetime
#先获得时间数组格式的日期
threeDayAgo = (datetime.datetime.now() - datetime.timedelta(days = 3))
#转换为时间戳:
timeStamp = int(time.mktime(threeDayAgo.timetuple()))
#转换为其他字符串格式:
otherStyleTime = threeDayAgo.strftime("%Y-%m-%d %H:%M:%S")
注:timedelta()的参数有:days,hours,seconds,microseconds
本文介绍了如何使用Python的datetime和time模块来获取当前时间的N天前的具体时间,并提供了将该时间转换为时间戳和自定义字符串格式的方法。
1400

被折叠的 条评论
为什么被折叠?



