【发布时间】:2020-06-28 13:33:23
【问题描述】:
我有一个时间戳字典,它是我首先转换为日期时间对象的字符串。
我需要做相当于timestamp at time zone 'UTC' at time zone 'America/New_York'的sql
这里我有一个for循环
for x in dataj:
x['event_time'] = datetime.strptime(x['event_time'].split('.')[0], "%Y-%m-%d %H:%M:%S")
x['event_time'] = x['event_time'].replace(tzinfo=timezone('America/New_York'))
我收到此错误
TypeError: timezone() argument 1 must be datetime.timedelta, not str
dataj 看起来像这样:
P(dataj[0])
{'$insert_id': '14ae91db-4b9e-4898-88dd-62fc9f99dcb4',
'$schema': 12,
'adid': None,
'event_time': '2019-12-01 00:00:19.251000'
}
【问题讨论】:
-
你能展示你的数据吗?
-
您确定您使用的是
pytz.timezone而不是datetime.timezone吗?
标签: python dictionary pytz