Convert UTC datetime string to local datetime

后端 未结 13 967
醉话见心
醉话见心 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=<UTC>)
    
    timezone.localtime(date)
    # datetime.datetime(2014, 8, 1, 16, 15, 0, 513000, tzinfo=<DstTzInfo 'America/New_York' EDT-1 day, 20:00:00 DST>)
    
    0 讨论(0)
提交回复
热议问题