Time.time ()
Returns the time as a floating-point number.
On Windows and most UNIX systems, the era is January 1, 1970 00:00:00 (UTC), and the leap second does not count toward the number of seconds since the epoch.
>>> time.time () 1508211081.817371>>> a = Time.time () >>> time.gmtime (a) Time.struct_time (tm _year=2017, tm_mon=10, tm_mday=17, tm_hour=3, tm_min=32, tm_sec=2, Tm_wday=1, tm_yday=290, tm_isdst=0)
You can use gmtime () to convert timestamps to a more friendly way
Time.gmtime ([second])
Converts the time in seconds from the epoch to the struct_time of UTC , where the DST flag is always zero.
If secs or none is not provided, the current time is returned using the date ().
>>> time.gmtime (0) time.struct_time (tm_year=1970, Tm_mon=1, Tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, Tm_wday =3, Tm_yday=1, tm_isdst=0) >>> time.gmtime () time.struct_time (tm_year=2017, tm_mon=10, tm_mday=17, Tm_hour=3, Tm_min=35, tm_sec=26, Tm_wday=1, tm_yday=290, tm_isdst=0)
Time.localtime ([second])
Like Gmtime (), but converted to local time . If secs or none is not provided, the current time is returned using the date ().
>>> Time.localtime (Time.struct_time) (tm_year=2017, tm_mon=10, tm_mday=17, tm_hour=11, tm_min=40, tm_sec=24, Tm_wday=1, tm_yday=290, tm_isdst=0)
Time.sleep (seconds)
Suspends execution of the calling thread. The parameter can be a floating-point number to indicate a more accurate sleep time.
Time.strftime (format [, T])
Converts the tuple or struct_time that represents the time returned by Gmtime () or localtime () to the string specified by the format parameter.
If T is not provided, the current time is returned using localtime ().
The format must be a string. If any of the fields in t exceed the allowable range, ValueError is raised.
>>> time.strftime ('%y-%m-%d ') ' 2017-10-17 '
Format table
instruction | meaning |Description=========================%a|the name of the weekday for the region abbreviation. %a|the full working day name of the locale. %b|abbreviated month name for the locale. %b|the full month name of the locale. %c|locale is the appropriate date and time representation. %d| The date of the decimal number [ on, to]. %h| Hour (24-hour system) is a decimal number [xx, at]. %i| Hour (12-hour system) is a decimal number [ on, A]. %j| Decimal number in the year [001,366]. %m| decimal number [ on, A]. %m| Minute is a decimal number [xx, -]. %p| The locale corresponds to AM or PM. (1)%s| The number of seconds is a decimal number [xx, A]。 (2)%u| The number of weeks in a year (Sunday as the first day of the week) is a decimal number [xx, -]。 All days of the new year before the first Sunday are considered to be in the No. 0 week. (3)%w| Weekday as decimal number [0(Sunday),6]. %w| The number of weeks in the year (Monday is Monday) is the decimal number [xx, -]。 All days of the new year before the first Monday are considered to be in the No. 0 week. (3)%x|the appropriate date representation for the locale. %x|the appropriate time representation of the locale. %y| Year without century as decimal number [xx, About]. %y|the year, the century is the decimal number. %z| The time zone offset, which represents a positive or negative difference in the HHMM or-hhmm format of UTC/GMT, where H represents a decimal hour number and M represents a decimal scale [- at: -,+ at: -]. %z|the time zone name (no characters, if no time zone exists). %% | Literal'%'Character.
Python Learning Time Module