溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

python的時間模塊

發(fā)布時間:2020-09-24 15:08:31 來源:網(wǎng)絡(luò) 閱讀:194 作者:依偎書生 欄目:編程語言
from datetime import datetime#導(dǎo)入模塊里面的當(dāng)前時間模塊
import  time
print(dir(datetime))
now_time = datetime.now()#獲得當(dāng)前的時間
print("now:{0}".format(now_time))
print('now day:{0}'.format(now_time.date()))#將時間格式化
print('now day:{0}'.format(now_time.time()))
print('now day:{0}'.format(now_time.today()))
print('now day:{0}'.format(now_time.year))
print('now day:{0}'.format(now_time.month ))
print(dir(now_time))
print(time.time())
print("--------------------------------------------------")
#自定義時間輸出
d= datetime(2020,10,30,14,6)
#時間日期字符串之間的轉(zhuǎn)換
ds = '2018/10/3'
ds_t=datetime.strptime(ds,'%Y/%m/%d')
print(ds_t)
print("---------------------------------------------------")
n=datetime.now()
print(n)
n_str = n.strftime('%Y/%m/%d%H:%M:%S')#轉(zhuǎn)換為字符串
print(n_str)
print(type(n_str))
print("----------------------------------------------------")
#datetime之間的加減操作
n = datetime.now()
n_next =n + timedelta (days=5,hours=42,minutes=4)
向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI