strftime year

Chris Gonnerman chris.gonnerman at newcenturycomputers.net
Sun Jan 27 11:18:29 EST 2002


"Anthony Tekatch" <tekatch at idirect.com> wrote in message
news:<AFU48.1035$9y2.118114 at news20.bellglobal.com>...
> strftime seems to improperly computer the year on the December
> 31, 2001:
>
> Here is an example program and it's output:
>
>
> #!/usr/local/bin/python
>
> import time,os
>
> os.environ['TZ']='EST5EDT'
>
> for offset in range(10):
>   time_flt=1009757224.0+(offset*3*3600)
>   print time_flt,
>   print time.strftime('%m/%d/%g %l:%M%P',time.localtime(time_flt))

Ah, on Linux (glibc) the %g operator returns the ISO 8601 year,
based on week numbers.  Just Say No and use %y/%Y instead.

Read the Python Library Reference and follow only the codes there
for portability.

> 1009757224.0 12/30/01  7:07pm
> 1009768024.0 12/30/01 10:07pm
> 1009778824.0 12/31/02  1:07am
> 1009789624.0 12/31/02  4:07am
> 1009800424.0 12/31/02  7:07am
> 1009811224.0 12/31/02 10:07am
> 1009822024.0 12/31/02  1:07pm
> 1009832824.0 12/31/02  4:07pm
> 1009843624.0 12/31/02  7:07pm
> 1009854424.0 12/31/02 10:07pm
>
>
> Note, December 31 should still be year "01".

Nope, 12/31 is in a different week, which is assigned to 2002.

> Am I doing something wrong?

Yup, 'fraid so.  See above.






More information about the Python-list mailing list