from datetime import datetime
from datetime import timedelta
(datetime.utcnow() + timedelta(seconds=60*30)).strftime('%Y-%m-%d %H:%M:%S')
Python: Current UTC plus 30 minutes
-
03-06-2023 - |
题
In Python, how can you get the current UTC time plus 30 minutes?
I tried this:
>>> import datetime
>>> future = datetime.datetime.now() + datetime.timedelta(seconds=30*60)
>>> str(datetime.timedelta(seconds=future))
'16133 days, 17:54:08' ----> output
I'm not sure this is correct (I'm sure I am wrong, Python newb here).
解决方案 2
其他提示
>>> import datetime
>>> datetime.datetime.utcnow() + datetime.timedelta(minutes=30)
datetime.datetime(2014, 3, 4, 18, 0, 49, 757000)
不隶属于 StackOverflow