概述
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中从日期时间减去秒所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复