python 进行日期倒计时

利用datetime来实现日期倒计时,具体代码如下:

from datetime import datetime
future = datetime.strptime('2022-06-30 08:00:00','%Y-%m-%d %H:%M:%S')
#当前时间
now=datetime.now()
#时间差
delta = future-now
hour = delta.seconds/60/60
minute = (delta.seconds -hour*60*60)/60
seconds=delta.seconds-hour*60*60 - minute*60
print_now=now.strftime('%Y-%m-%d %H:%M:%S')
print("现在是北京时间: ",print_now)
print("距离6月30号 \"你的目标内容\"结余天数:",delta.days)
# print("\结余天数\":delta.days,hour,minute,seconds)   

结果:

现在是北京时间:  2022-06-10 11:03:32
距离630"你的目标内容"结余天数: 19

猜你喜欢

转载自blog.csdn.net/m0_46400195/article/details/125217792
今日推荐