[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Help %A in time.strftime(%A

Jolly

12/20/2007 12:59:00 AM

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.
2 Answers

Gabriel Genellina

12/20/2007 1:39:00 AM

0

En Wed, 19 Dec 2007 21:59:25 -0300, jolly <jemnader@gmail.com> 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#l2...
%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

Ben Finney

12/20/2007 2:23:00 AM

0

jolly <jemnader@gmail.com> 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.or....

Searching that reference, you'll find the documentation for the time
module <URL:http://docs.python.org/lib/module-tim... and
specifically the time.strftime function
<URL:http://docs.python.org/lib/module-time.html#l2... 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