Do you know how to use the modules in Python stuct_time to provide more than N types? The following article describes how to use the Code related to how to operate the time function in the Python stuct_time module.
I. The module in Python stuct_time provides various operation time functions. There are two methods:
First, the timestamp is unique compared to the offset calculated in seconds at 00:00:00 on January 1 ,.
Second, it is represented as an array (struct_time). There are nine elements, respectively, indicating that the stuct_time of the same timestamp varies with the time zone.
Time zone: Time Zone and UTC time zone functions:
- asctime()
- asctime([tuple]) -> string
Converts a Python struct_time to a string clock (). This function has two functions: the actual running time of the program is returned during the first call, and the total running time of the entire program is returned ), after the second call, the returned time is the interval from the first call to the current call. Example:
- import time
- if __name__ == '__main__':
- time.sleep(1)
- print "clock1:%s" % time.clock()
- time.sleep(1)
- print "clock1:%s" % time.clock()
- time.sleep(1)
- print "clock1:%s" % time.clock()
Output:
- clock1:3.07301626324e-006
- clock1:0.997576228264
- clock1:1.99513653272
- 1.1.3 sleep(seconds)
The thread delays running at a specified time. It has been tested and measured in seconds.
- ctime(seconds)
- ctime(seconds) -> string
Converts a timestamp Python stuct_time (current time by default) into a time string. Example:
- if __name__ == '__main__':
- print time.ctime()
Output:
- Thu Mar 04 12:55:03 2010
- 1.1.5 gmtime(...)
- gmtime([seconds]) -> (tm_year, tm_mon, tm_day,
tm_hour, tm_min,tm_sec, tm_wday, tm_yday, tm_isdst)
(9 parameter values) converts a timestamp into a struct_time of UTC time zone (0 Time Zone). If the seconds parameter is not input, the current time is the time value of the standard array type) example:
- if __name__ == '__main__':
- print time.gmtime()
Time tuples output:
- (2010, 3, 4, 4, 58, 53, 3, 63, 0)
The returned data is an array type. The meanings are as follows:
- (tm_year, tm_mon, tm_day, tm_hour, tm_min,tm_sec, tm_wday, tm_yday, tm_isdst)
After an array is obtained, we can split it like this: print time. gmtime () [0] to get the first element value.