博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
time,datetime,时间戳 时间格式转换
阅读量:7033 次
发布时间:2019-06-28

本文共 622 字,大约阅读时间需要 2 分钟。

总结:

time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")

几个概念

时间戳:整型或floattime对象,datetime对象字符串 := '2015-06-06 10:10:10'

时间戳<-->struct_time

time_struct = time.localtime(timestamp)timestamp = time.mktime(time_struct)

struct_time<-->字符串

time.strftime("%Y-%m-%d %H:%M:%S", st)time.strptime(st, "%Y-%m-%d %H:%M:%S")

时间戳<-->datetime

datetime.datetime.fromtimestamp(ts)dt.timestamp()

datetime<-->字符串

dt.strftime("%Y-%m-%d %H:%M:%S.%f")datetime.strptime(dt, "%Y-%m-%d %H:%M:%S.%f")ps:datetime转time对象:datetimeObj.timetuple()

 

转载于:https://www.cnblogs.com/willaty/p/8005848.html

你可能感兴趣的文章