Python 日期转化
import time
- (当前)时间戳(秒为单位,精确到毫秒)
timestamp = time.time()
- (当前)时间结构体
timestruct = time.localtime()
- 时间戳 -> 时间结构体
timestruct = time.localtime(timestamp)
- 时间结构体 -> 时间戳
timestamp = time.mktime(timestruct)
- 时间结构体 -> 时间字符串
timestr = time.strftime("%Y.%m.%d_%H:%M:%S", timestruct)
- 时间字符串 -> 时间结构体
timestruct = time.strptime(timestr, "%Y.%m.%d_%H:%M:%S")
- 时间戳 -> 时间字符串
timestr = time.strftime("%Y.%m.%d_%H:%M:%S", time.localtime(timestamp))
- 时间字符串 -> 时间戳
timestamp = time.mktime(time.strptime(timestr, "%Y.%m.%d_%H:%M:%S"))