datetime.now()
doesn't appear to have timezone info attached. I want the current time in UTC. What do I do?
>>> from datetime import datetime
>>> y = datetime.now()
>>> y
datetime.datetime(2014, 3, 11, 11, 18, 33, 598489)
At first I thought datetime.utcnow()
was the obvious solution, but then I discovered that it doesn't have timezone info attached either (WTF?).
>>> from datetime import datetime
>>> y = datetime.utcnow()
>>> y
datetime.datetime(2014, 3, 11, 16, 19, 40, 238810)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…