How to convert datetime.date.today() to UTC time?
Question:
How to make sure the datetime.date.today()
is converted to UTC time?
This is my code so far:
#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")
Answers:
for printing date with time you can use …
tomorrow = twtomorrow.strftime("%Y-%m-%d %H:%M:%S")
instead of
tomorrow = twtomorrow.strftime("%Y-%m-%d")
Use utcnow
:
today = datetime.datetime.utcnow().date()
How to make sure the datetime.date.today()
is converted to UTC time?
This is my code so far:
#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")
for printing date with time you can use …
tomorrow = twtomorrow.strftime("%Y-%m-%d %H:%M:%S")
instead of
tomorrow = twtomorrow.strftime("%Y-%m-%d")
Use utcnow
:
today = datetime.datetime.utcnow().date()