Python調用time模塊設置當前時間-指定時間


import datetime
import time
#新建元旦時間
#將程序打包
def A():
# 設定時間
newyear =datetime.datetime(2033,10,1)
#調用當前時間
nowtime=datetime.datetime.now()
#計算時間差
#計算設定的時間減去現在的時間等於多少天
delte =newyear - nowtime
#將算出的天數除於365天,則是剩余年數
year=int(delte.days/365)
#將計算出的天數用%算出余數則是,算除n年多少天
day=int(delte.days%365)
#計算小時
hour=int(delte.seconds/60/60)
#計算分
minute=int((delte.seconds - hour*60*60)/60)
#計算秒
seconds = delte.seconds - hour*60*60 - minute*60
#輸出
print("距離 2033年10月1日\t剩余:%d年,%d天,%d時,%d分,%d秒" % (year,day, hour, minute, seconds))
#打包設置循環,循環輸出剩余時間,sleep(1):美妙循環一次
while True:
time.sleep(1)
A()


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM