首页 > 编程语言 > 详细

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

时间:2019-12-13 13:36:33      阅读:363      评论:0      收藏:0      [点我收藏+]

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 = time1.mktime()

下图为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()

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

原文:https://www.cnblogs.com/wukongball/p/12034154.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!