python时间处理

a1 = "2019-5-10"
# 先转换为时间数组
timeArray = time.strptime(a1, "%Y-%m-%d")
# 转换为时间戳
timeStamp = int(time.mktime(timeArray))
dt = datetime.fromtimestamp(timeStamp)
# 当前时间
timeStamp = time.time()
dt2 = datetime.fromtimestamp(timeStamp)
a = dt2 - dt
b = dt - dt2
print(dt2 - dt)
print(dt - dt2)
posted @ 2023-09-07 10:55  bitterteaer  阅读(3)  评论(0编辑  收藏  举报