First, the time format commonly used
1. Timestamp format, for example: T = 1523197272.9467547 (s), in seconds;
2. Structured time format, for example:
T=time.struct_time (tm_year=2018,tm_mon=4,tm_mday=8,tm_hour=22,tm_min=22,tm_sec=4,tm_wday=6,tm_yday=98, TM_ISDST =0), which contains the year, month, day, time, minutes, seconds, days of the week (0 for Monday) and so on;
Therefore, you can arbitrarily remove the desired value, such as:
In fact, Time.localtime () is based on Time.time (), which is based on a timestamp, which omits time.time (), such as:
Is it identical??
3. String time format, for example: 2018-04-08 23:52:59.563715, as shown in:
Two or three direct conversion of time formats
1. Time stamp conversion to structured time
Use Time.localtime () or Time.localtime (Time.time ()) directly to convert timestamps into structured time, such as:
2. Structured time conversion to timestamp
Use Time.mktime (structured time) to convert the structured time to a timestamp, as shown in:
3. Conversion between string time and structured time
3.1 Turn the structured time into a string time
With function Time.strftime (ARG1,ARG2), the first parameter arg1 must be a format type that is eventually converted to a string time and is a string, and the second parameter arg2 must be structured time, for example:
Time.strftime ("%y-%m-%d%h:%m:%s", TL), as shown in:
Python format symbols in time Date:
The simplest way to remember: uppercase, lowercase, and seconds.
3.2 Convert string time to structured time
Using the function Time.strptime (ARG1,ARG2), the first parameter arg1 must be the string time to convert, the second parameter arg2 the first parameter arg1 the corresponding structured time format (i.e.: The link between the ARG2 format must be the same as the link between the Arg1 string time, and the format content must be the same, not more than one less, otherwise will error), for example:
Time.strftime ("2017-12-23 13:23:26", "%y-%m-%d%h:%m:%s") or Time.strftime ("2017:12:23 13:23:26", "%Y:%m:%d%H:%M:%S"), As shown in the following:
Third, other
1.time.sleep ()
For example: Time.sleep (2) indicates that the thread sleeps for 2 seconds, in seconds;
2.datetime Module
A common format is: Datetime.datetime.now () indicates the output current time, as shown in:
Python Common Time Module explained