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()


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM