Question about strftime

Discussion in 'Python' started by silverburgh.meryl@gmail.com, Feb 10, 2007.

  1. Guest

    Hi,

    I have question about strftime. I am trying to print the current time
    in this format:

    date = strftime("%Y%m%d_%H%M%S", gmtime())
    print date

    I run the script at 2:18 pm, but I get this: 20070210_201837

    Can you please tell me why I get '20'? instead of '14' (which is 2:00
    pm)?

    Thank you.
    , Feb 10, 2007
    #1
    1. Advertising

  2. Paul Rubin Guest

    writes:
    > date = strftime("%Y%m%d_%H%M%S", gmtime())
    > print date
    >
    > I run the script at 2:18 pm, but I get this: 20070210_201837
    > Can you please tell me why I get '20'? instead of '14' (which is 2:00
    > pm)?


    Wrong time zone? Maybe you want localtime() instead of gmtime().
    Paul Rubin, Feb 10, 2007
    #2
    1. Advertising

  3. On 10 Feb 2007 12:29:52 -0800, declaimed the
    following in comp.lang.python:


    > Can you please tell me why I get '20'? instead of '14' (which is 2:00
    > pm)?
    >

    Because you are using GREENWICH MEAN TIME as the input and are
    located somewhere in US CST zone...

    >>> import time
    >>>
    >>>
    >>> t0 = time.time()
    >>> g0 = time.gmtime(t0)
    >>> l0 = time.localtime(t0)
    >>> print time.strftime("%Y%m%d_%H%M%S", g0)

    20070210_205307
    >>> print time.strftime("%Y%m%d_%H%M%S", l0)

    20070210_125307
    >


    I'm in PST zone
    --
    Wulfraed Dennis Lee Bieber KD6MOG

    HTTP://wlfraed.home.netcom.com/
    (Bestiaria Support Staff: )
    HTTP://www.bestiaria.com/
    Dennis Lee Bieber, Feb 10, 2007
    #3
  4. En Sat, 10 Feb 2007 17:29:52 -0300, <> escribió:

    > I have question about strftime. I am trying to print the current time
    > in this format:
    >
    > date = strftime("%Y%m%d_%H%M%S", gmtime())
    > print date
    >
    > I run the script at 2:18 pm, but I get this: 20070210_201837
    >
    > Can you please tell me why I get '20'? instead of '14' (which is 2:00
    > pm)?


    gmtime() returns the time in UTC, not local time, and your computer thinks
    you're in Mexico, central USA or Canada.

    --
    Gabriel Genellina
    Gabriel Genellina, Feb 10, 2007
    #4
    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. Bryan O'Malley

    strftime not working as expected

    Bryan O'Malley, Feb 3, 2004, in forum: C++
    Replies:
    8
    Views:
    2,615
    Jerry Coffin
    Feb 17, 2004
  2. Bimal
    Replies:
    1
    Views:
    453
    Tim Prince
    Aug 20, 2003
  3. Richard Shea

    strftime - %a is always Monday ?

    Richard Shea, Dec 29, 2003, in forum: Python
    Replies:
    5
    Views:
    1,057
    Richard Shea
    Dec 30, 2003
  4. Allen Unueco

    time.strftime Timezone issue

    Allen Unueco, Jun 13, 2004, in forum: Python
    Replies:
    1
    Views:
    352
    Allen Unueco
    Jun 13, 2004
  5. Tim Peters

    RE: time.strftime Timezone issue

    Tim Peters, Jun 13, 2004, in forum: Python
    Replies:
    1
    Views:
    746
    Allen Unueco
    Jun 13, 2004
Loading...

Share This Page