I have an int variable that are actually seconds (lets call that amount of seconds X). I need to get as result current date and time (in datetime format) minus X seconds.
Example
If X is 65 and current date is 2014-06-03 15:45:00, then I need to get the result 2014-06-03 15:43:45.
Environment
I'm doing this on Python 3.3.3 and I know I could probably use the datetime module but I haven't had any success so far.
解决方案
Using the datetime module indeed:
import datetime
X = 65
result = datetime.datetime.now() - datetime.timedelta(seconds=X)
You should read the documentation of this package to learn how to use it!
最后
以上就是正直牛排最近收集整理的关于python当前时间减去指定时间_在python中从日期时间减去秒的全部内容,更多相关python当前时间减去指定时间_在python中从日期时间减去秒内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复