python查缺補漏:python的time模塊

# author:閆振興
# contact: [email protected]
# datetime:2020/4/12 21:46
# software: PyCharm
"""
文件說明:
"""
#encoding:utf-8
import datetime
#datetime.datetime獲取當前時間
print(datetime.datetime.now())
#獲取三天後的時間
print(datetime.datetime.now()+datetime.timedelta(+3))
#獲取三天前的時間
print(datetime.datetime.now()+datetime.timedelta(-3))
#獲取三個小時後的時間
print(datetime.datetime.now()+datetime.timedelta(hours=3))
#獲取三分鐘以前的時間
print(datetime.datetime.now()+datetime.timedelta(minutes = -3))
# 只獲得年月日
print(datetime.datetime.now().date())
#按照格式獲得年月日時分秒
print(datetime.datetime.now().strftime("%Y-%m-%d %H-%M-%S"))
d1 = datetime.datetime(2020,4,12)
d2 = datetime.datetime(2020,2,12)
interval = d2 - d1
print(interval.days)



# author:閆振興
# contact: [email protected]
# datetime:2020/4/12 21:33
# software: PyCharm
"""
文件說明:
"""
#encoding:utf-8
import time
#time.time() 時間戳
print(time.time())
# 格式化時間
print(time.strftime("%Y/%m-%d"))
# 結構化時間(以元組的形式)
print(time.localtime())
# 將時間轉換成utc格式的元組格式:
print(time.gmtime())
#結構化時間(元組)轉換成 字符串時間
print(time.strftime('%Y/%m-%d', time.localtime()))
#將格字符串時間轉換成結構化時間 元組:
print(time.strptime('2020-04-12', '%Y-%m-%d'))
#將時間戳轉成 英文字符串時間
print(time.ctime(time.time()))

t1 = time.time()
print("t1=:"+str(t1))               #1483495728.4734166
print(time.ctime(t1))   #Wed Jan  4 10:08:48 2017
t2 = time.localtime()
print("t2=:"+str(t2))

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章