获取时间的方法
datetime.date.today() + datetime.timedelta(-1)
(datetime.datetime.now() + relativedelta(days = -1)).strftime("%d")
(datetime.datetime.now()+datetime.timedelta(minutes=1)).strftime("%Y-%m-%d %H:%M:%S")
2022-03-23 10:45:21
(datetime.datetime.now()-datetime.timedelta(minutes=1)).strftime("%Y-%m-%d %H:%M:%S")
2022-03-23 10:43:21
(datetime.datetime.now()+datetime.timedelta(hours=1)).strftime("%Y-%m-%d %H:%M:%S")
2022-03-24 10:42:06
(datetime.datetime.now()-datetime.timedelta(hours=1)).strftime("%Y-%m-%d %H:%M:%S")
2022-03-23 06:43:21
(datetime.datetime.now()+datetime.timedelta(days=1)).strftime("%Y-%m-%d %H:%M:%S")
2022-03-24 10:43:58
(datetime.datetime.now()-datetime.timedelta(days=1)).strftime("%Y-%m-%d %H:%M:%S")
2022-03-22 10:43:58
时间戳的转时间
timeStamp = 1648027635
timeArray = time.localtime(timeStamp)
otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
结果:
2022-03-23 17:27:15
timeStamp = 1638441354453
timeStamp_py = int(timeStamp/1000)
timeArray = time.localtime(timeStamp_py)
otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
结果:
2021-12-02 18:35:54
数据补全时间
otherStyleTime ='2022-01-14'
uploadTime = datetime.strptime(otherStyleTime, "%Y-%m-%d")
otherStyleTime1 ='20220114'
uploadTime1 = datetime.strptime(otherStyleTime1, '%Y%m%d')
otherStyleTime2 ='2022年01月14日'
uploadTime2 = datetime.strptime(otherStyleTime2, '%Y年%m月%d日')
结果:
2022-01-14 00:00:00
2022-01-14 00:00:00
2022-01-14 00:00:00
|