python中time和datetime,对同一个时间戳给出了两个不同的日期时间
问题描述:
import datetime
import time
if __name__ == "__main__":
timenow = 1670923800
ot=datetime.datetime.utcfromtimestamp(timenow).strftime("%Y-%m-%dT%H:%M:%S")
print(ot)
#输出ot=2022-12-13T09:30:00
print(datetime.datetime.strptime("2022-12-13T09:30:00", "%Y-%m-%dT%H:%M:%S").timestamp())
#输出1670895000.0
print("======================")
timea=time.localtime(timenow)
ot=time.strftime("%Y-%m-%dT%H:%M:%S", timea)
print(ot)
#输出2022-12-13T17:30:00
print("=======================")
strtime="2022-12-13T09:30:00"
print(time.mktime(time.strptime(strtime, "%Y-%m-%dT%H:%M:%S")))
#输出1670895000.0
所以为啥时间戳为1670923800会算出来日期是2022-12-13 09:30:00呢?它应该是下午17:30才对啊