将日期转换为 JSON 时,javascript 以这种格式保存日期:
2012-05-29T19:30:03.283Z
但是,我不确定如何将其放入 python 日期时间对象中。我试过这些:
# Throws an error because the 'Z' isn't accounted for:
datetime.datetime.strptime(obj[key], '%Y-%m-%dT%H:%M:%S.%f')
# Throws an error because '%Z' doesn't know what to do with the 'Z'
# at the end of the string
datetime.datetime.strptime(obj[key], '%Y-%m-%dT%H:%M:%S.%f%Z')
我相信javascript正在以官方ISO格式保存字符串,所以似乎应该有办法让pythondatetime.strptime()
读取它?