datetime and tzinfo

Discussion in 'Python' started by John Hunter, Sep 16, 2004.

  1. John Hunter

    John Hunter Guest

    I am using the tzinfo classes from the datetime docs, eg UTC,
    USTimeZone, and the instantiations Pacific, Central, Eastern, etc. I
    would like to take a datetime instance in the UTC timezone and
    construct the equivalent in another time zone.

    Eg, if I am given dt1 in the example below, and the timezone Central

    dt1 = datetime(2004, 9, 12, 14, 22, 24, tzinfo=UTC())

    I would like to construct the datetime instance dt2

    dt2 = datetime(2004, 9, 12, 9, 22, 24, tzinfo=Central)

    which is the same time in a different timezone.

    >>> dt1 = datetime(2004, 9, 12, 14, 22, 24, tzinfo=UTC())
    >>> dt2 = datetime(2004, 9, 12, 9, 22, 24, tzinfo=Central)
    >>> dt1-dt2

    datetime.timedelta(0)

    I've read through the docs at
    http://www.python.org/doc/2.3.2/lib/datetime-tzinfo.html but none of
    the methods looked just right.

    Is there an easy/right way to do this?

    Thanks,
    John Hunter
     
    John Hunter, Sep 16, 2004
    #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. Tino Lange
    Replies:
    1
    Views:
    459
    Lawrence D'Oliveiro
    Apr 3, 2006
  2. Cong Ma
    Replies:
    0
    Views:
    456
    Cong Ma
    Dec 8, 2008
  3. Cong Ma
    Replies:
    0
    Views:
    419
    Cong Ma
    Dec 9, 2008
  4. Michael Torrie
    Replies:
    0
    Views:
    405
    Michael Torrie
    Mar 12, 2010
  5. aspineux
    Replies:
    3
    Views:
    306
    aspineux
    Oct 21, 2011
Loading...

Share This Page