Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Help %A in time.strftime(%A)

Reply
Thread Tools

Help %A in time.strftime(%A)

 
 
jolly
Guest
Posts: n/a
 
      12-20-2007
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.
 
Reply With Quote
 
 
 
 
Gabriel Genellina
Guest
Posts: n/a
 
      12-20-2007
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

 
Reply With Quote
 
 
 
 
Ben Finney
Guest
Posts: n/a
 
      12-20-2007
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help Help Help Pentax S5i Help needed (Please) The Martian Digital Photography 14 06-20-2008 07:56 AM
HELP - HELP - HELP =?Utf-8?B?S2ltb24gSWZhbnRpZGlz?= ASP .Net 4 03-09-2006 12:46 PM
HELP WANTED HELP WANTED HELP WANTED Harvey ASP .Net 1 07-16-2004 01:12 PM
HELP WANTED HELP WANTED HELP WANTED Harvey ASP .Net 0 07-16-2004 10:00 AM
HELP! HELP! HELP! Opening Web Application Project Error =?Utf-8?B?dHJlbGxvdzQyMg==?= ASP .Net 0 02-20-2004 05:16 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57