tags:

views:

180

answers:

2

I am using: datetime.now() to get the current time in an Event app that lets you create an event that has an end date, then all of the events are displayed in a calendar and if an event is passed due it is displayed in red.

My issue is that I have some users in different timezones than me saying that the events are ending at the wrong time. They should end at midnight on the day they are due.

I have the timezone setup in my django settings.py. When I use: datetime.now() is that going off of the users local timezone or is it going off of what timezone I have setup in django?

What I want is to find midnight for the users current timezone, so if my method above is wrong, how do I go about doing that?

Thanks

+1  A: 

You will need your users to specify their timezone in their user profile. This can then be used to calculate local times correctly.

Check out Relativity of time – shortcomings in Python datetime, and workaround for some good information (and concrete examples).

John Keyes
Nice link, thanks for the help.
Joe
A: 

Try storing the Utc Datetime instead then make the necessary adjustments based on the user's timezone.

import datetime

def getUtcNow(): return datetime.datetime(*time.gmtime()[:6])

dannyroa