How to convert datetime.date.today() to UTC time?
如何确保
到目前为止这是我的代码:
1 2 3 4 5 6 7 8 9 | #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") |
使用
1 | today = datetime.datetime.utcnow().date() |
随着时间的推移打印日期,你可以使用...
1 | tomorrow = twtomorrow.strftime("%Y-%m-%d %H:%M:%S") |
代替
1 | tomorrow = twtomorrow.strftime("%Y-%m-%d") |