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