time module question - time zones

Discussion in 'Python' started by Eric Wertman, May 21, 2008.

  1. Eric Wertman

    Eric Wertman Guest

    I tend to deal with dates a lot in different formats and places...
    typically I'll convert them to a time tuple with strptime(), and pass
    them around like that before I need to write them back out.

    One set of time/dates I'm getting are in UTC, but the string doesn't
    say that specifically. So I do this.. I had expected the outcome to
    be offset properly (I'm EST5EDT). But I'm obviously missing
    something:

    #!/usr/bin/env python

    import time

    utc_str = '2008-05-10 03:05:00 UTC'

    d = time.strptime(utc_str,'%Y-%m-%d %H:%M:%S %Z')
    t = time.mktime(d)

    print d
    print time.gmtime(t)
    print time.localtime(t)

    output :

    (2008, 5, 10, 3, 5, 0, 5, 131, 0)
    (2008, 5, 10, 8, 5, 0, 5, 131, 0)
    (2008, 5, 10, 4, 5, 0, 5, 131, 1)


    I believe that I should be getting (2008, 5, 9, 23, 5, 0, 5, 130, 1)
    out of one of those, since the original 3:05am time was UTC, and my TZ
    is currently -4. Does that make sense? I didn't even think I needed
    to do any business with time.localtime() and time.gmtime(). I
    expected time.strftime() to return the locale appropriate time, but
    it didn't.

    TIA

    Eric
     
    Eric Wertman, May 21, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. CJ
    Replies:
    2
    Views:
    583
  2. Craig

    Time Zones?

    Craig, Jan 17, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    616
    Craig
    Jan 19, 2006
  3. Eric Wertman

    Re: time module question - time zones

    Eric Wertman, May 21, 2008, in forum: Python
    Replies:
    0
    Views:
    505
    Eric Wertman
    May 21, 2008
  4. Harlan Messinger

    Dates, time zones,daylight saving time

    Harlan Messinger, Apr 15, 2010, in forum: ASP .Net
    Replies:
    1
    Views:
    1,017
    Eric Isaacs
    Apr 16, 2010
  5. David Graham

    cookie expire time and time zones

    David Graham, Nov 20, 2003, in forum: Javascript
    Replies:
    6
    Views:
    271
    Dr John Stockton
    Nov 22, 2003
Loading...

Share This Page