(一)通用)时间包
1、日期字符串=时间戳int
将导入时间#时间字符串转换为时间戳int dt=' 2016-05-0520336028336054 ' #时间数组timearray=time.strptime(dt,' % y-% m-% d
2、时间戳=日期字符串
准确到(1)秒
将导入时间#时间戳int转换为时间字符串timestamp=1462451334#, 将local time time _ local=time.local time (timestamp )转换为新的时间格式(652016-05-)的dt=time.strftime(%y-%m-%d )
)2)精确到毫秒ms
导入时间CT=time.time (# CT=1536994867.99991837打印) CT )打印(int (CT ) ) local_time=time.localtime ) )
eftimestamp2datems(timestamp ) :“”时间戳是准确转换为ms的日期字符串。 单位s :param timestamp:时间戳:return:日期字符串' ' local _ time=time.local time (timestamp ) )。 data _ head=time.strftime (% y-% m-% d % h : % m : % s ),local_time ) data_secs ) timestamp-int
3、获取当前时间的时间戳
time.time () )
(二)其他:日期包
1 .每日输出格式datetime=string
importdatetimenow=datetime.datetime.now (now.strftime (' % y-% m-% d % h : % m 3360 % s ' ) strftime为datetime
2 .每日输出格式string=datetime
importdatetimet _ str=' 2015-04-0719336011336021 ' d=datetime.datetime.strp time (t _ str,' %y-%m-%d
3 .将自由形式时间字符串转换为时间戳
导入日期GMT _ format=' % a,% d % b % y % h : % m : % sgmt ' time=' thu,19 feb 200916336007 GMT ' time
转载于:https://www.cn blogs.com/Andy 9468/p/7992261.html