Pfu, no idea. This is the first time I've heard of pytz, to be honest
:-) But I'd assume that whenever you create a new datetime object with
a given timezone, it should consider the DST setting. Haven't tried it
though on any library.

-- Horst

On Wed, Jun 11, 2008 at 11:03 AM, Darthmahon <[EMAIL PROTECTED]> wrote:
> Ahhh ok, does this handle daylight saving for you automatically do you
> know?
>
> Overall looks pretty useful, but I wonder how this differs to pytz:
>
> http://pytz.sourceforge.net/
>
> Do they do the same thing? Just different implementations?
>
> Thanks for your help so far though :)
>
> On Jun 11, 8:59 am, "Horst Gutmann" <[EMAIL PROTECTED]> wrote:
>> Ah ok, sorry, I misunderstood what you're trying to achieve :-)
>>
>> from dateutil.tz import gettz
>> import datetime
>>
>> now = datetime.datetime.now(tz=gettz('UTC'))
>>
>> >> datetime.datetime(2008, 6, 11, 7, 57, 36, 812305, 
>> >> tzinfo=tzfile('/usr/share/zoneinfo/UTC'))
>>
>> london_time = gettz('Europe/London')
>>
>> >>> now.astimezone(london_time)
>>
>> datetime.datetime(2008, 6, 11, 8, 57, 36, 812305,
>> tzinfo=tzfile('/usr/share/zoneinfo/Europe/London'))
>>
>> This is using the dateutil package available 
>> onhttp://labix.org/python-dateutil
>>
>> In general datetime.astimezone does probably what you want, but you
>> have to make sure, that the datetime object you're working with, has a
>> timezone associated with it. If you know what timezone it's supposed
>> to have (yet is lacking the timezone attribute itself), you can easily
>> attach a timezone like this:
>>
>> mydatetime.replace(tzinfo=gettz('CEST')) # associated mydatetime with
>> the CEST timezone
>>
>> I hope this helps :-)
>>
>> -- Horst
>>
>> On Wed, Jun 11, 2008 at 9:45 AM, Darthmahon <[EMAIL PROTECTED]> wrote:
>> > Hmm kinda. Basically, users on my site can select their timezone. As
>> > there are events on the site, I want the time of these events to be
>> > displayed based on their timezone. I.E. if an event is at 10PM GMT, a
>> > user in New York should see it as 5PM EST.
>>
>> > I could do this as a template tag, but I want to do it in the view
>> > level as there is logic that needs this information to pull out the
>> > right events and the right time.
>>
>> > I've had a look at the link you sent, written in a way I don't
>> > understand though :( Any real world examples?
>>
>> > I basically just need to split this:
>>
>> > now = datetime.utcnow()
>>
>> > Into this:
>>
>> > 2002, 10, 27, 6, 0, 0,
>>
>> > I guess it needs to be a string though as I need to wrap it in this:
>>
>> > utc_dt = datetime(2002, 10, 27, 6, 0, 0, tzinfo=utc)
>>
>> > Cheers,
>> > Chris
>>
>> > On Jun 10, 10:06 pm, "Horst Gutmann" <[EMAIL PROTECTED]> wrote:
>> >> You mean like the difference in seconds between 2 timezones? Then
>> >> perhaps the tzinfo class itself might be of some help here. It has a
>> >> utcoffset(self, datetime) method that returns a datetime.timedelta
>> >> instance:http://docs.python.org/lib/datetime-tzinfo.html
>>
>> >> - Horst
>>
>> >> On Tue, Jun 10, 2008 at 10:17 PM, Darthmahon <[EMAIL PROTECTED]> wrote:
>> >> > Hi Guys,
>>
>> >> > I want to convert a UTC timestamp so I can use it to figure out what
>> >> > offset a certain user has based on their selected timezone. I'm using
>> >> > the Python pytz module by the way.
>>
>> >> > Here is the code so far:
>>
>> >> > ==========
>>
>> >> > # get users time
>> >> > timezone = timezone('America/New_York')
>>
>> >> > # get UTC time
>> >> > now = datetime.utcnow()
>> >> > now.strftime()
>>
>> >> > # begin timezone conversion
>> >> > utc_dt = datetime(now, tzinfo=utc)
>>
>> >> > # this is the date and time to print
>> >> > fmt = '%Y-%m-%d %H:%M:%S %Z%z'
>> >> > tz = utc_dt.astimezone(timezone)
>> >> > tz.strftime(fmt)
>>
>> >> > ==========
>>
>> >> > The problem I am having is converting utc_dt into a format I can use.
>> >> > I've seen examples that do this:
>>
>> >> > utc_dt = datetime(2002, 10, 27, 6, 0, 0, tzinfo=utc)
>>
>> >> > But the problem is how do I get my now variable into that format?
>>
>> >> > Cheers,
>> >> > Chris
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to