Introduction
Notes on the Python3 time
package.
Import Module
Get the Timestamp of the Current Time
Convert Timestamp to a Time Tuple
1
| t = time.localtime(time.time())
|
Get Elements from the Time Tuple
Year
Month
Day of the Month
Day of the Year
Hour
Minute
Second
- Range: [0, 60] (including leap seconds [0, 61])
Weekday
Daylight Saving Time (DST)
Values
-1
: Default value, unknown
1
: DST is in effect
0
: DST is not in effect
Convert Time to a String
Built-in
Custom
1
| time.strftime("%Y-%m-%d %H:%M:%S", t)
|
Convert String to Time
Built-in
<str>
: String
1
| t = time.mktime(time.strptime(<str>,"%a %b %d %H:%M:%S %Y"))
|
Custom
<str>
: String
1
| t = time.mktime(time.strptime(<str>,"%Y-%m-%d %H:%M:%S"))
|
Conclusion
References
菜鸟笔记
CSDN——洛城-sola