Convert UTC datetime string to local datetime

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

    If using Django, you can use the timezone.localtime method:

    from django.utils import timezone
    date 
    # datetime.datetime(2014, 8, 1, 20, 15, 0, 513000, tzinfo=)
    
    timezone.localtime(date)
    # datetime.datetime(2014, 8, 1, 16, 15, 0, 513000, tzinfo=)
    

提交回复
热议问题