我正在尝试使用strptime方法将格式为"2012-07-24T23:14:29-07:00"的时间戳转换为python中的datetime对象.问题在于结束时的时间偏移(-07:00).没有偏移我可以成功做到
time_str = "2012-07-24T23:14:29"
time_obj=datetime.datetime.strptime(time_str,'%Y-%m-%dT%H:%M:%S')
Run Code Online (Sandbox Code Playgroud)
但随着我尝试的抵消
time_str = "2012-07-24T23:14:29-07:00"
time_obj=datetime.datetime.strptime(time_str,'%Y-%m-%dT%H:%M:%S-%z').
Run Code Online (Sandbox Code Playgroud)
但是它给出了一个Value错误,说"z"是一个糟糕的指令.
任何解决方案的想法?
我有一个JSON对象的字符串表示形式.
dumped_dict = '{"debug": false, "created_at": "2020-08-09T11:24:20"}'
Run Code Online (Sandbox Code Playgroud)
当我用这个对象调用json.loads时;
json.loads(dumped_dict)
Run Code Online (Sandbox Code Playgroud)
我明白了
{'created_at': '2020-08-09T11:24:20', 'debug': False}
Run Code Online (Sandbox Code Playgroud)
这里没有错.但是,我想知道是否有办法将上面的对象与json.loads转换为如下所示:
{'created_at': datetime.datetime(2020, 08, 09, 11, 24, 20), 'debug': False}
Run Code Online (Sandbox Code Playgroud)
不久,我们能够在调用json.loads时将datetime字符串转换为实际的datetime.datetime对象吗?
使用Python,有没有办法检查dateMongoDB集合中文档的字段是ISO格式还是字符串格式?