您好,登錄后才能下訂單哦!
#time模塊
'''
struct_time
/ \
/ \
/ \ localtime
strftime / strptime \ gttime
/ \
/ \
/ mktine \
/ \
/ \
format_time timestamp
(time.time)
%Y%m%D%H%M%S字符串
/ \
asctime / \ ctime
/ \
/ \
struct_time timestamp
'''
import time
print(time.time()) # 1562067574.5663896
print(time.mktime(time.localtime())) # 1562067651.0
print(time.localtime())
#time.struct_time(tm_year=2019, tm_mon=7, tm_mday=2, tm_hour=19, tm_min=41,
#tm_sec=24, tm_wday=1, tm_yday=183, tm_isdst=0)
print(time.gmtime())
#time.struct_time(tm_year=2019, tm_mon=7, tm_mday=2, tm_hour=19, tm_min=41,
#tm_sec=24, tm_wday=1, tm_yday=183, tm_isdst=0)
print(time.strptime('2017-2-2 16:16:16','%Y-%m-%d %H:%M:%S'))
#time.struct_time(tm_year=2017, tm_mon=2, tm_mday=2, tm_hour=16, tm_min=16,
#tm_sec=16, tm_wday=3, tm_yday=33, tm_isdst=-1)
print(time.strftime('%Y-%m-%d %X')) # 2019-07-02 19:46:45
print(time.strftime('%Y-%m-%d %X',time.localtime())) #2019-07-02 19:47:25
#星期
print(time.strftime('%a')) # Tue
print(time.strftime('%A')) # Tuesday
#月份
print(time.strftime('%b')) # Jul
print(time.strftime('%B')) # July
#時間日期都有
print(time.strftime('%c')) # Tue Jul 2 19:51:55 2019
#一月的第幾天
print(time.strftime('%d')) # 02
#小時
print(time.strftime('%H')) # 19
#一年的等幾天
print(time.strftime('%j')) # 183
#月份
print(time.strftime('%m')) # 07
#分鐘
print(time.strftime('%M')) # 54
#AM或者PM
print(time.strftime('%p')) # PM
#秒
print(time.strftime('%S')) # 14
#第幾個星期
print(time.strftime('%U')) # 26
#一星期的第幾天
print(time.strftime('%w')) # 2
#星期一為一個星期的開始
print(time.strftime('%W')) # 26
#相應的日期和時間
print(time.strftime('%x')) # 07/02/19
print(time.strftime('%X')) # 19:57:24
#年
print(time.strftime('%y')) # 19
print(time.strftime('%Y')) # 2019
#夏令時
print(time.strftime('%z')) # +0800
print(time.strftime('%%')) # %
print(time.strftime('%x %X')) # 07/02/19 20:06:24
t1 = time.time()
print(t1+10) # 1562069264.919341
#datetime相當于對time模塊進行了封裝
import datetime
import time
d1 = datetime.date(2011,6,3)
print(d1.weekday()) # 4
print(d1.isoweekday()) # 5
print(d1.isocalendar()) # (2011, 22, 5)
print(datetime.datetime.now()) # 2019-07-02 20:22:54.840992
print(datetime.datetime.today()) # 2019-07-02 20:23:35.791064
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。