strftime - %a is always Monday ?
__peter__ at web.de
Mon Dec 29 14:54:25 CET 2003
Richard Shea wrote:
> Hi - I'm trying to use strftime to output the day of the week but I
> find that I always get told it's Monday. I have tried day, month, year
> etc and all come out correctly but as soon as I use %a I get 'Mon'.
> I'm running Python 2.3.2 on a Windows 98 machine. Can anyone suggest
> what the problem might be please ?
> This is a segment of the code which is manfests the behaviour ...
>>>> from time import localtime,strftime,time
>>>> lst1 = ['2003','12','27']
>>>> strftime("%A,%d (%w %y
> 'Monday,27 (1 03 12)'
> ... whereas the 27th was a Saturday ?
Garbage in garbage out. Only the 7th element of the tuple is used to
generate the string:
>>> for wd in range(7):
... print time.strftime("%a", (0,0,0,0,0,0,wd,0,0))
The cleanest solution uses the new datetime module instead:
>>> import datetime
>>> datetime.date(2003, 12, 27).strftime("%a")
More information about the Python-list