python - getmtime() 与 datetime.now():
问题描述
此代码每年在时钟转换的晚上(欧洲中部夏令时间到欧洲中部时间)打印一次错误警告:
import os
import datetime
now = datetime.datetime.now()
age = now - datetime.datetime.fromtimestamp(os.path.getmtime(file_name))
if (age.seconds + age.days * 24 * 3600) < -180:
print('WARN: file has timestap from future?: %s' % age)
即使在每年一小时的时钟轮班期间,如何使此代码工作?
更新
我只关心年龄,而不关心日期时间。
解决方案
推荐阅读
- regex - 如何在正则表达式中替换未知数量的模式重复?
- javascript - Line breaks in the syntax highlighting view when using highlight.js
- java - Graphic Calendar in Java
- kubernetes - GKE 集群突然无法自动缩放节点池
- google-cloud-platform - Unable to download edge browser on Google Chrome VM
- python - 随机森林:预测 vs predict_proba
- azure - Publishing using MSDeploy to Azure App from a different computer updates all the files
- javascript - 如何实现 ExpressJS 错误处理,以便针对不同的 HTTP 状态代码显示不同的错误
- android - Android Studio Emulator doesn’t open the app
- bash - 尝试通过传递 listweb.txt 来制作一个 ping .sh 脚本以查看网络是否还活着