python datetime seconds和时间元组格式转换

python 输出时间格式转换:

datetime: 输出格式为 class

如:datetime.datetime.now()

1. time class转换为time tuple类型

使用timetuple()

time = datetime.datetime.now()

time1 = time.timetuple()

2. timetuple转换为seconds格式

使用time模块的方法mktime()

time2 = time.mktime(time1)

下图为time模块的几种格式的转换方法:

官网链接:https://docs.python.org/2/library/time.html#module-time

From To Use
seconds since the epoch struct_time in UTC gmtime()
seconds since the epoch struct_time in local time localtime()
struct_time in UTC seconds since the epoch calendar.timegm()
struct_time in local time seconds since the epoch mktime()
posted @ 2019-12-13 11:25  桃月火兔  阅读(1802)  评论(0)    收藏  举报