Help %A in time.strftime(%A)

J

jolly

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.
 
G

Gabriel Genellina

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.
 
B

Ben Finney

jolly said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top