Convert UTC datetime string to local datetime

后端 未结 13 1119
醉话见心
醉话见心 2020-11-22 05:37

I\'ve never had to convert time to and from UTC. Recently had a request to have my app be timezone aware, and I\'ve been running myself in circles. Lots of information on co

13条回答
  •  不知归路
    2020-11-22 06:03

    From the answer here, you can use the time module to convert from utc to the local time set in your computer:

    utc_time = time.strptime("2018-12-13T10:32:00.000", "%Y-%m-%dT%H:%M:%S.%f")
    utc_seconds = calendar.timegm(utc_time)
    local_time = time.localtime(utc_seconds)
    

提交回复
热议问题