Parsing a Datetime String into a Django DateTimeField

前端 未结 5 1832
盖世英雄少女心
盖世英雄少女心 2020-12-05 06:30

I have a Django app with a model that contains a field of type DateTimeField.
I am pulling data from the web in the format of 2008-04-10 11:47:58-05.
I

5条回答
  •  情歌与酒
    2020-12-05 07:26

    I've been using this:

    from django.utils.timezone import get_current_timezone
    from datetime import datetime
    tz = get_current_timezone()
    dt = tz.localize(datetime.strptime(str_date, '%m/%d/%Y'))
    

提交回复
热议问题