Help %A in time.strftime(%A)

Discussion in 'Python' started by jolly, Dec 20, 2007.

  1. jolly

    jolly Guest

    Hey guys,

    I'm following a tutorial on Python and I came across this in one of
    the examples.

    import time

    today = time.localtime(time.time())
    theDate = time.strftime("%A %B %d", today)

    print today
    print theDate


    Result:


    (2007, 12, 20, 9, 48, 15, 3, 354, 1)
    Thursday December 20


    can someone explain to me the %A and the %B?

    Thanks.
    jolly, Dec 20, 2007
    #1
    1. Advertising

  2. En Wed, 19 Dec 2007 21:59:25 -0300, jolly <> escribió:

    > I'm following a tutorial on Python and I came across this in one of
    > the examples.
    >
    > import time
    >
    > today = time.localtime(time.time())
    > theDate = time.strftime("%A %B %d", today)
    >
    > print today
    > print theDate
    >
    >
    > Result:
    >
    >
    > (2007, 12, 20, 9, 48, 15, 3, 354, 1)
    > Thursday December 20
    >
    >
    > can someone explain to me the %A and the %B?


    The format is documented in the Library Reference, at
    <http://docs.python.org/lib/module-time.html#l2h-2816>
    %A is Locale's full weekday name (Thursday in your example)
    %B is Locale's full month name (December in your example)

    If you want to see how all other formats work:

    import time
    import string

    now = time.localtime()
    for char in string.ascii_letters:
    fmt = "%"+char
    try:
    result = time.strftime(fmt, now)
    except:
    pass
    else:
    if result:
    print "%s\t%s" % (fmt, result)

    This is my output:

    %a Wed
    %b Dec
    %c 12/19/07 22:31:40
    %d 19
    %j 353
    %m 12
    %p PM
    %w 3
    %x 12/19/07
    %y 07
    %z Hora est. de Sudamérica E.
    %A Wednesday
    %B December
    %H 22
    %I 10
    %M 31
    %S 40
    %U 50
    %W 51
    %X 22:31:40
    %Y 2007
    %Z Hora est. de Sudamérica E.

    --
    Gabriel Genellina
    Gabriel Genellina, Dec 20, 2007
    #2
    1. Advertising

  3. jolly

    Ben Finney Guest

    jolly <> writes:

    > import time
    >
    > today = time.localtime(time.time())
    > theDate = time.strftime("%A %B %d", today)
    > [...]
    >
    > can someone explain to me the %A and the %B?


    Your first resort for more information about the standard library
    should be the online standard library reference
    <URL:http://docs.python.org/lib/>.

    Searching that reference, you'll find the documentation for the time
    module <URL:http://docs.python.org/lib/module-time.html> and
    specifically the time.strftime function
    <URL:http://docs.python.org/lib/module-time.html#l2h-2816> which
    describes the format codes it expects.

    --
    \ "Democracy is the art of running the circus from the monkey |
    `\ cage." -- Henry L. Mencken |
    _o__) |
    Ben Finney
    Ben Finney, Dec 20, 2007
    #3
    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. Allen Unueco

    time.strftime Timezone issue

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

    RE: time.strftime Timezone issue

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

    RE: time.strftime Timezone issue

    Tim Peters, Jun 13, 2004, in forum: Python
    Replies:
    0
    Views:
    664
    Tim Peters
    Jun 13, 2004
  4. jolly

    Help %A in time.strftime(%A)

    jolly, Dec 20, 2007, in forum: Python
    Replies:
    0
    Views:
    268
    jolly
    Dec 20, 2007
  5. Greg Krohn
    Replies:
    1
    Views:
    934
    Denis Kasak
    Feb 17, 2009
Loading...

Share This Page