[Tutor] datetime, time zones, and ISO time
Kent Johnson
kent37 at tds.net
Wed Feb 17 21:26:03 CET 2010
On Wed, Feb 17, 2010 at 3:12 PM, David Perlman <dperlman at wisc.edu> wrote:
> Yeah, I got this part. The thing that's hanging me up is that there doesn't
> seem to be any way to get a tzinfo instance that contains the current local
> time zone information. You can do time.timezone to get the seconds from
> UTC, but there doesn't seem to be any way to convert that into a tzinfo! I
> would be perfectly satisfied with this:
>
> tz=offset_to_tzinfo(time.timezone) # or whatever
> aware_now=datetime.datetime.now(tz)
> print aware_now.isoformat()
>
> I'm pretty sure that would give me what I want, but there doesn't seem to be
> any way to do step one without subclassing tzinfo. This makes me feel like
> I MUST be missing something obvious, because it shouldn't require so much
> coding just to find out what the current local time and timezone is!
The docs make it clear that you do have to subclass tzinfo, that no
implementations are provided.
It sounds like you want the LocalTimezone class in the examples at the
bottom of this section - "A class capturing the platform's idea of
local time":
http://docs.python.org/library/datetime.html#tzinfo-objects
Kent
More information about the Tutor
mailing list