您好,登錄后才能下訂單哦!
#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
#相應(yīng)的日期和時間
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相當(dāng)于對time模塊進(jìn)行了封裝
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
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。