参考:https://blog.csdn.net/sxf_123456/article/details/81582964

 

参考模板:

from datetime import datetime, timedelta

 

result = datetime.strptime('2018-08-06T10:00:00.000Z', "%Y-%m-%dT%H:%M:%S.%fZ")

local_time = result + timedelta(hours=8)

print(local_time)

 

实际使用:

我是因为要将阿里云的时间改为本地时间,所以将上面的模板稍微改下即可。

from datetime import datetime, timedelta

 

result = datetime.strptime('2018-08-06T10:00Z', "%Y-%m-%dT%H:%MZ")

local_time = result + timedelta(hours=8)

print(local_time)

 

注意:上面的local_time在print时,会显示为字符串格式,但local_time变量本身是一个datetime对象,通过type(local_time)可以得知。

有时候我们想得到实实在在的字符串格式,而不是datetime对象,需要改成这样:

print(local_time.__str__())

或者

return local_time.__str__()

 

相关文章:

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