time模块— Time access and conversions
Jupter notebook NBViewer传送门
This module provides various time-related functions.
Functions
time.asctime([t])
Convert a tuple
or struct_time
representing a time as returned by gmtime() or localtime() to a string of the following form: 'Sun Jun 20 23:21:05 1993'
. If t is not provided, the current time as returned by localtime() is used. Locale information is not used by asctime().
1 | import time |
Wed Apr 24 15:34:33 2019
Wed Apr 24 15:34:33 2019
time.ctime([secs])
Convert a time expressed in seconds since the epoch to a string representing local time.
If secs is not provided or None, the current time as returned by time()
is used. ctime(secs)
is equivalent to asctime(localtime(secs))
. Locale information is not used by ctime()
.
1 | time.ctime(datetime.datetime.now().timestamp()) |
'Wed Apr 24 15:36:47 2019'
time.gmtime([secs])
Convert a time expressed in seconds since the epoch to a struct_time
in UTC in which the dst flag is always zero. If secs is not provided or None, the current time as returned by time() is used. Fractions of a second are ignored. See above for a description of the struct_time object. See calendar.timegm() for the inverse of this function.
1 | time.gmtime(datetime.datetime.now().timestamp()) |
time.struct_time(tm_year=2019, tm_mon=4, tm_mday=24, tm_hour=7, tm_min=39, tm_sec=19, tm_wday=2, tm_yday=114, tm_isdst=0)