import time
import datetime
print(datetime.datetime.now())
today = datetime.date.today()
print(today)
yesterday = today + datetime.timedelta(days=-1)
print(yesterday)
tomorrow = today + datetime.timedelta(hours=24)
print(tomorrow)
## 时间戳转换为datatime
timestamp = 1628618820043
time_data = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(timestamp)/1000))
print(time_data)
## ISO时间转化为datatime,时间时钟加8h
iso_time = "2021-02-28T22:39:36"
print("ISO_TIME:", iso_time)
data_data = datetime.datetime(*time.strptime(iso_time, "%Y-%m-%dT%H:%M:%S")[:3])
print(data_data)
data_time = datetime.datetime(*time.strptime(iso_time, "%Y-%m-%dT%H:%M:%S")[:6])
print(data_time)
print(data_time + datetime.timedelta(hours=8))
结果显示:
2022-01-07 19:37:34.588644
2022-01-07
2022-01-06
2022-01-08
2021-08-11 02:07:00
ISO_TIME: 2021-02-28T22:39:36
2021-02-28 00:00:00
2021-02-28 22:39:36
2021-03-01 06:39:36
网友评论