time,datetime,时间戳 时间格式转换
总结:
time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")
几个概念
时间戳:整型或float time对象,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()
【本文章出自博客园willaty,转载请注明作者出处,误差欢迎指出~】