Domanda

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).

È stato utile?

Soluzione 2

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

Altri suggerimenti

>>> import datetime
>>> datetime.datetime.utcnow() + datetime.timedelta(minutes=30)
datetime.datetime(2014, 3, 4, 18, 0, 49, 757000)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top