python3 5月26日 time模块常用时间转换

import time 

获取当前时间:

指定字符串格式:time.strftime("%Y-%m-%d %H:%M:%S")

当前时间戳:time.time()

当前时间元组格式:time.localtime()

字符串转时间格式

将时间字符串转按指定格式换为元组<class 'time.struct_time'>
time.strptime(“字符串”,format("%Y-%m-%dT%H:%M:%SZ"))

将时间格式转换为时间戳:
time.mktime(‘class 'time.struct_time’格式的元组) #将时间格式元组转换为时间戳 <class 'float'>

time.gmtime(时间戳)将时间戳转换为UTC时间元组
time.localtime(时间戳)将时间戳转换为本地时区的时间元组

time.ctime(‘时间戳’)将时间戳转换为字符串(本地时间)    如Sat May 26 21:11:24 2018

time.asctime(时间元组)将时间格式元组转换为 特定固定格式字符串  如Sat May 26 21:11:24 2018

 

猜你喜欢

转载自www.cnblogs.com/zhangmingda/p/9094373.html