Convert UTC datetime string to local datetime

后端 未结 13 955
醉话见心
醉话见心 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:06

    You can use arrow

    from datetime import datetime
    import arrow
    
    now = datetime.utcnow()
    
    print(arrow.get(now).to('local').format())
    # '2018-04-04 15:59:24+02:00'
    

    you can feed arrow.get() with anything. timestamp, iso string etc

提交回复
热议问题