[Tips] python time模板的时间格式

在import time模块后,可以获得各种格式的时间输出。

典型的过程如下:

import time
#获得当前时间时间戳,下面now的int数值就是时间戳
now = int(time.time())
#转换为其他日期格式,如:"%Y-%m-%d %H:%M:%S"
timeArray = time.localtime(now)
otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)

  

上面获得otherStyleTime就是根据需要的日期格式转换好的时间字符串。

原文地址:https://www.cnblogs.com/immortalBlog/p/12869503.html