Several commonly used modules

# ! / Usr / bin / env Python 
# - * - Coding: UTF-8 - * - 
# **************************** ******* tmie module *********************************** 
# HTTPS: // docs .python.org / 3 / Library / time.html highlight = time% 20clock # time.process_time? 

# usually represents a time of three kinds of methods in python: 
# timestamp: timestamp indicates that the January 1, 1970 00:00:00 start offset calculated in seconds; 
# formatted time string; 
# structured time (struct_time): structured time a total of nine elements tuple element :( total of nine year, month, day, hour, minute, second, the first few weeks of the year, day of the year, daylight saving time) 
# Import time 
# 1.time.time () # returns the current timestamp in seconds 
# Print (time .time ()) 

# the time stamp is converted to a structured 
# 2.time.localtime ([secs]) # a time stamp into a structured current time zone, the default parameters of the current time stamp
# Print (time.localtime ()) 
# a time.struct_time (tm_year = 2019, = 12 is tm_mon, tm_mday =. 19, tm_hour =. 4, tm_min = 20 is, tm_sec = 49, = tm_wday. 3, tm_yday = 353, the tm_isdst = 0) 
# default format of time inside the structure above is: "% a% B% D% H:% M:% S% the Y" 

# 3.time.gmtime ([secs]) # converted to a timestamp to UTC ( Coordinated Universal time), 0:00 zones, default parameters for the current timestamp 
# Print (time.gmtime ()) 

# the structured time into a timestamp 
# 4.time.mktime (t) # struct_time into a timestamp 
# Print (time.mktime (time.localtime ())) 

# conversion between time and the formatted string structured time 
# 5.time.strptime (string [, the format]) # a formatted string time structured into time 
# Print (the time.strptime ( "2019-12-19 04:16:30", "%% Y-X-M-% D%")) 

#6. time.strftime (format [, t] ) # a structured time into a tuple formatted time string 
# Print (The time.strftime ( "% D%% Y-X-M-%", Time. localtime ())) 

# 7.time.seelp () # thread postpone a specified time after the operation, in seconds 
# the time.sleep (3) 
# Print ( "already after three seconds") 

# 8. time.asctime ([t]) # indicates a structured time tuple represents: Thu On Dec. 19 04:10:21 2019 
# Print (that time.asctime (time.localtime ())) 

# 9.time.ctime ([ secs]) # a timestamp (in seconds calculated by a float) into that time.asctime () form 
# Print (time.ctime (1,886,699,927)) On Oct 15 03:18:47 Mon # 2029 
# Print (Time. ctime ()) # default parameters of the time.time (). 19 Thu on Dec 2019 04:12:22 

# 10 time.clock () this method is eliminated # python3.3
# Note: On UNIX systems, it returns the timestamp, represents the CPU time, in seconds 
#       in WINDOWS, the return of the first call is the actual running time of the process, after the second call is after the call from the first run to the present time, i.e. the time difference between the two 
# 11.time.perf_counter () calculates the time.sleep # () time; return performance counter value, the clock having the highest resolution available, can be measured shorter duration 
# 12.time.process_time () # will not calculate time.sleep () time; and the current process of system and user CPU time value (in seconds) 
# Print ( "it's time .time () method} {. "the format (the time.time ())) 
# Print (" it is time.perf_counter () method} {. "the format (time.perf_counter ())) 
# Print (" it is time .process_time () method} {. "the format (time.process_time ())) 
# A1 = the time.time () 
# B1 = time.perf_counter () 
# C1 = time.process_time () 
# S =. 1 
# for i in range(99):
#     s*=i
# time.sleep(2)
# a2 = time.time()
# b2 = time.perf_counter()
# c2 = time.process_time()
# print("-"*15 + ">"*15)
# print("time.time()方法用时为{}".format(str(a2-a1)))
# print("time.perf_counter()方法用时为{}".format(b2-b1))
# print("time.process_time()方法用时为{}".format(c2-c1))

# 13.datetime模块
# import datetime
# print(datetime.datetime.now())        #2019-12-19 04:59:17.887542
time module

Guess you like

Origin www.cnblogs.com/shichenyang/p/12065641.html