문제

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

from datetime import datetime
from datetime import timedelta
(datetime.utcnow() + timedelta(seconds=60*30)).strftime('%Y-%m-%d %H:%M:%S')

다른 팁

>>> import datetime
>>> datetime.datetime.utcnow() + datetime.timedelta(minutes=30)
datetime.datetime(2014, 3, 4, 18, 0, 49, 757000)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top