我有05:55:13
格式的文件时间,我想在其中添加当前日期2017-04-27
。然后我想用UTC格式的grafana,但似乎有四舍五入。这将如何运作?
我为05:55:13
和05:56:13
获得相同的输出。
import datetime
import time
line = str(datetime.date.today()) + " " + "05:55:13"
naive = datetime.datetime.strptime(line, '%Y-%m-%d %H:%M:%S')
utc_dt = naive.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')
print naive
print utc_dt
line = str(datetime.date.today()) + " " + "05:56:13"
naive = datetime.datetime.strptime(line, '%Y-%m-%d %H:%M:%S')
utc_dt = naive.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')
print naive
print utc_dt
答案 0 :(得分:0)
您正在呼叫utcnow
returns current date and time in UTC
timezone。当然你有相同的输出。不使用此方法使用您的代码:
line = str(datetime.date.today()) + " " + "05:55:13"
naive = datetime.datetime.strptime(line, '%Y-%m-%d %H:%M:%S')
utc_dt = naive.strftime('%Y-%m-%dT%H:%M:%SZ')
print naive
print utc_dt
line = str(datetime.date.today()) + " " + "05:56:13"
naive = datetime.datetime.strptime(line, '%Y-%m-%d %H:%M:%S')
utc_dt = naive.strftime('%Y-%m-%dT%H:%M:%SZ')
print naive
print utc_dt