Collection time a python


** The following are my personal understanding, if you find an error or questions can contact me to discuss **
#### Python representation of four time: 1 format time strings 2. 3. timestamp time Ganso 4. time Object
- string_time, refers to a time string format string parameter ** formatted output format and output parameters are specified relative position, and the format is similar to the role of the python, the common time format string: ** "% Y-% m-% d % H:% M:% S% z,% a,% A,% b,% B,% c,% I,% p" ** see documents other code , C strftime library function.

Name | Meaning | value |
--- | --- | ---
% the Y-| in | particular year, for example: 2019
% m | months | 01-12
% d | date | 01-31
when | |% H 01 -31
% M | min | 00,59
% S | s | 00,61
% Z | timezone |
% a | the abbreviated name of the locale weekday |
% a | weekday the complete name of the locale |
% B | the abbreviated month name locale |
% B | the full month name of the locale |
% C | accordance with the appropriate date and time representation locale |
% the I | of a few hours (12 hour) | 01-12
% p | locale | AM or PM
Tucao about the official website comment range is 0-59 seconds, can be measured 0-61

- Timestamp, string, or timestamp refers to coding information for identifying recorded date and time, Wikipedia can not be explained and easy to understand, my understanding is ** from 1 January 1970 to the present number of seconds elapsed ** .

- struct_time, is time tuples ** ** ancestral means 9 comprises special elements, (tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday, tm_isdst), see below table

Name | Meaning | value |
--- | --- | ---
tm_year | in | particular year, for example: 2019
tm_mon | months | 1-12
tm_mday | date | 1-31
when | | tm_hour 1-23
tm_min | points | 0-59
tm_sec | s | 0-61
tm_wday | week | 0-6 (from the weekend)
tm_yday | first few days of the year | 1-666
tm_isdst | whether daylight saving time | -1,0, 1 (true value can be represented and the flase)
- time_object, ** refers to the time the object is generated by a certain object class ** time, e.g. datetime.
#### python time in two modules: 1.time 2.datetime

1.time ###
- Constants
- Variables with simple values, values of simple variable
- altzone, -32 400
- Daylight, 0
- TimeZone, -28.8 thousand
- _STRUCT_TM_ITEMS, 11
- the Variables with Complex values, the value of complex variables
- tzname but if direct calls will get a garbled value, can not read, access to information discovery can see the real value by re-encoding and decoding, it is thanks to this love to think of bloggers here, here codec reference to his blog, this blog here : https: //www.cnblogs.com/luo630/p/9555684.html, which is more telling
`` `Python
>>> time.tzname [0] .encode ( '. 1-Latin') decode ( '. GBK ')
' Chinese standard time '
>>> time.tzname [. 1] .encode ('. 1-Latin ') decode (.' GBK ')
' Chinese daylight saving time '
`` `
- method:
- the asctime: time element group is converted to a string, when no incoming parameters, call localtime () returns the current time, parameter types: tuples, return type: string. For example:
`` `Python
>>> Import Time
>>>

>>> time.asctime ((2019,6,11,16,7,40,59,59,59)) # here must wear a tuple of nine numbers, date and time division must comply logic, must be less than equal to 61 seconds, I do not know why 61, temporarily not figure out the logic behind the three, but the date should be in front of the face related to
'Thu Jun 11 16:07:40 2019'
`` `
- Clock: timer function, return at the end of the process the first call to the function uses the time from the beginning to the return type: float. For example:
`` `Python
>>> time.clock ()
5E-07
>>> the time.sleep (. 1)
>>> time.clock ()
11.9833418
>>> the time.sleep (10)
>>> time.clock ()
35.1999596
`` `
- the ctime: converting the timestamp to the local time in units of strings. Equivalent asctime (localtime (seconds)). When no incoming parameters, use localtime () returns the current time. Parameter Type: timestamp, return type: string. For example:
`` `Python
>>> time.ctime (1,555,555,550)
'18 is Thu On Apr 2019 10:45:50'
>>> time.ctime ()
'

- get_clock_info ()



- gmtime: The time stamp is converted to time Ganso, when no incoming parameters, returns the current time World Time Ganso. Parameter types: timestamp, return type: Ganso (see the source code but only one pass). For example:
`` `Python
>>> time.gmtime (1,555,555,550)
a time.struct_time (tm_year = 2019, = tm_mon. 4, tm_mday = 18 is, tm_hour = 2, 45 = tm_min, tm_sec = 50, = tm_wday. 3, tm_yday = 108 , the tm_isdst = 0)
>>> time.gmtime ()
a time.struct_time (tm_year = 2019, tm_mon =. 6, tm_mday =. 11, tm_hour =. 9, 18 is tm_min =, = 54 is tm_sec, tm_wday =. 1, tm_yday = 162, the tm_isdst 0 =)
`` `

- localtime: gmtime with similar functions, but the return time becomes local time. For example:
`` `Python
>>> time.localtime (1,555,555,550)
a time.struct_time (tm_year = 2019, = tm_mon. 4, tm_mday = 18 is, tm_hour = 10, 45 = tm_min, tm_sec = 50, = tm_wday. 3, tm_yday = 108 , the tm_isdst = 0)
>>> time.localtime ()
a time.struct_time (tm_year = 2019, tm_mon =. 6, tm_mday =. 11, tm_hour =. 17, tm_min = 28, = 34 is tm_sec, tm_wday =. 1, tm_yday = 162, the tm_isdst = 0)
`` `
- the mktime: time conversion Ganso timestamp, returns a time stamp. Parameter Type: Time tuples (9 elements), the return type: timestamp. For example:
`` `Python
>>> time.mktime ((2019,4,18,10,45,50,3,108,0))
1,555,555,550.0
` ``
- Monotonic: a monotonous timer can not be turned. Do not know when to begin the return type: float. For example:
`` `Python
>>> DEF FUNC ():
... Print (time.monotonic ())
... the time.sleep (. 1)
...
>>> I = 0
>>> the while I <. 5 :
... FUNC ()
... + = I. 1
...
461,875.89
461,876.89
461,877.89
461,878.89
461 879.
89 `` `
- perf_counter: Performance counters for benchmarking. Dissatisfied run sub! Return type: float. E.g:
`` Python `
>>> time.perf_counter ()
3674.2299851
>>> time.perf_counter ()
3675.2086447
>>> time.perf_counter ()
3675.9990329
` ``
process time for analysis:: - process_time kernel and user space CPU time Sum. Return type: float. For example:
`` `Python
>>> time.process_time ()
4.40625
` ``

- SLEEP: The execution delay in seconds. Parameter Type: int or float, return type: None, this is not waste time demonstrates ...


- the strftime:
`` `
The time format specification tuple into a string. About formatting codes, see the library reference manual. When no incoming parameters, use localtime () returns the current time. Incoming parameters: match string, time tuples (string matching), Return parameter: time string
`` `
Example: `
`` Python
# generates the corresponding time of the foregoing character string format string
>>> time .strftime ( "% D%% Y-M-% H:% M:% S", (2019,. 1,. 1,. 1,. 1,. 1,. 1, 13 is, 0))
'2019-01-01 01: 01:01 '
The time.strftime >>> ( "% D%% Y-M-% H:% M:% S% the I", (2019,. 1,. 1,. 1,. 1,. 1,. 1, 13 is, 0))
'2019 01:01:01 01 -01-01 '
>>> The time.strftime ( "% D%% Y-M-% H:% M:% S% Z,% A,% A,% B,% B, C%, the I%,% P ", (2019,. 1,. 1,. 1,. 1,. 1,. 1, 13 is, 0))
'2019-01-01 01:01:01 + 0800, Tue, on Tuesday, Jan, january, Tue Jan 01:01:01. 1 2019,01, AM '
`` `

- the strptime: `
``
according to the format specification string as a time resolved tuples. About formatting codes, see the library reference manual (and strftime ()). Incoming parameters: time string, string matching. Return parameter: the time ancestral
`` `
Example: `
`` Python
>>> the time.strptime ( "2019-01-01 01:01:02", "% D%% Y-M-% H:% M:% S ")
a time.struct_time (tm_year = 2019, tm_mon =. 1, tm_mday =. 1, tm_hour =. 1, tm_min =. 1, tm_sec = 2, tm_wday =. 1, tm_yday =. 1,
-1 = the tm_isdst) `` `

- Time: in seconds to return the current time from the beginning of the era. If the system clock to provide this information, then there may be only a fraction of a second. We often say that the time stamp. Return parameter: float

Guess you like

Origin www.cnblogs.com/silencehuliang/p/11010372.html