最近写后端接口,调用外部API,拿到的时间格式为2019-08-18T16:00:00.000000Z,需要把它转换成常见的时间格式

解决方法:

1、转换成时间戳

expired_at='2019-08-18T16:00:00.000000Z'
expired_time_stamp = datetime.datetime.strptime(expired_at, '%Y-%m-%dT%H:%M:%S.000000Z')

时间格式‘%Y-%m-%dT%H:%M:%S.000000Z’一定要写对,Z前面的0的个数一定要保持一致,否则会报错

2、转换成常见格式

expired_time = datetime.datetime.strftime(expired_time_stamp, '%Y-%m-%d %H:%M:%S')

至此,完成

相关文章:

  • 2022-01-23
  • 2022-01-09
  • 2021-08-26
  • 2021-12-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-20
猜你喜欢
  • 2021-11-01
  • 2022-12-23
  • 2021-10-21
  • 2021-11-27
  • 2021-11-23
  • 2022-12-23
  • 2021-12-22
相关资源
相似解决方案