-46 learning python time module

Time Module

 

???? timestamp

print(time.time())

operation result:

1 1564294158.0389376
2 
3 Process finished with exit code 0

 

 

 

Structured time ?????

Print (time.localtime ())          # local time on 
the y-= time.localtime ()
 Print (y.tm_year)
 Print (y.tm_wday) 

Print (time.gmtime ()) # World Standardization time UTC

operation result:

time.struct_time(tm_year=2019, tm_mon=7, tm_mday=28, tm_hour=14, tm_min=25, tm_sec=57, tm_wday=6, tm_yday=209, tm_isdst=0)
2019
6
time.struct_time(tm_year=2019, tm_mon=7, tm_mday=28, tm_hour=6, tm_min=25, tm_sec=57, tm_wday=6, tm_yday=209, tm_isdst=0)

Process finished with exit code 0

 

 

 

····· structured into a timestamp Time

print(time.mktime(time.localtime()))

 

 

`` `` `` Structured time into a string time

print(time.strftime('%Y-%m-%d %X',time.localtime()))

operation result:

2019-07-28 14:34:58

Process finished with exit code 0

 

 

 

`` `` `` String is converted into a structured time period

print(time.strptime('2018:1:1:12:00:00','%Y:%m:%d:%X'))

operation result:

time.struct_time(tm_year=2018, tm_mon=1, tm_mday=1, tm_hour=12, tm_min=0, tm_sec=0, tm_wday=0, tm_yday=1, tm_isdst=-1)

Process finished with exit code 0

 

 

······ structured to convert time to express a string fixed

print(time.asctime())
print(time.ctime())

operation result:

Sun Jul 28 14:43:45 2019
Sun Jul 28 14:43:45 2019

Process finished with exit code 0

 

 

???? postpone run

print(time.sleep(1))

 

 

ps:

import datetime module


print(datetime.datetime.now())

 

Guess you like

Origin www.cnblogs.com/liujinjing521/p/11258973.html