python获取当前时间字符串_python获取当前时间

一、time模块

import time

# 生成timestamp

time.time()

# 1477471508.05

#struct_time to timestamp

time.mktime(time.localtime())

#生成struct_time

# timestamp to struct_time 本地时间

time.localtime()

time.localtime(time.time())

# time.struct_time(tm_year=2016, tm_mon=10, tm_mday=26, tm_hour=16, tm_min=45, tm_sec=8, tm_wday=2, tm_yday=300, tm_isdst=0)

# timestamp to struct_time 格林威治时间

time.gmtime()

time.gmtime(time.time())

# time.struct_time(tm_year=2016, tm_mon=10, tm_mday=26, tm_hour=8, tm_min=45, tm_sec=8, tm_wday=2, tm_yday=300, tm_isdst=0)

#format_time to struct_time

time.strptime('2011-05-05 16:37:06','%Y-%m-%d %X')

# time.struct_time(tm_year=2011, tm_mon=5, tm_mday=5, tm_hour=16, tm_min=37, tm_sec=6, tm_wday=3, tm_yday=125, tm_isdst&#

你可能感兴趣的:(python获取当前时间字符串)