How to convert datetime.date.today () to UTC?

How to make sure datetime.date.today() converted to UTC?

This is my code:

 #today : 2014-12-21 today = datetime.date.today() #1900-01-01 16:00:00+00:00 timeformat = datetime.datetime.strptime('16:00', '%H:%M').replace(tzinfo=pytz.utc) #combine today and timeformat 2014-12-21 16:00:00 now = datetime.datetime.combine(u, timeformat.time()) str_now = now.strftime("%Y-%m-%d %H:%M:%S") 
+7
python pytz
source share
2 answers

Use utcnow :

 today = datetime.datetime.utcnow().date() 
+16
source share

print date with time that you can use ...

 tomorrow = twtomorrow.strftime("%Y-%m-%d %H:%M:%S") 

instead

 tomorrow = twtomorrow.strftime("%Y-%m-%d") 
-4
source share

All Articles