R.J. Jackson
R.J. Jackson

Reputation: 125

Python Django: Time Zone Conversion

I'm parsing an XML file that has the dates in GMT time. It's my first time working with timezones so I'm having some difficulty displaying the right time. In the XML file the date is like this.

2015-06-29 23:05

I set up my model with a basic datetime field like this:

date = models.DateTimeField()

...my settings.py has:

 USE_TZ = True
 TIME_ZONE = 'America/Toronto'

However when I display the time via views it shows 3:05. Not exactly sure what I'm suppost to do next.

Upvotes: 1

Views: 1309

Answers (1)

Peyman
Peyman

Reputation: 3087

Well, there is no way to determine the time zone of the date time you provided. If you know that it is always GMT, then convert from GMT to your local time zone which is "America/Toronto" in your case.

If possible, I'd recommend changing the date format in your XML. Use UTC, as it provides time zone info.

Check this link out: Python - Convert UTC datetime string to local datetime

Readings I recommend for dealing with time. UTC: http://www.w3.org/TR/NOTE-datetime Django Time Zone Docs: https://docs.djangoproject.com/en/1.8/topics/i18n/timezones/

Upvotes: 1

Related Questions