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