[Tutor] Python time hour formatting
tpc at csua.berkeley.edu
tpc at csua.berkeley.edu
Fri Mar 26 11:20:11 EST 2004
hi Eric,
argh! You're right. What's frustrating is that I would like to implement
this feature on a Window's machine, to print at the beginning of each
error log entry. It works just fine in Linux as you say, but not at all
in Windows. Arrgh I say !
On Thu, 25 Mar 2004, Eric Culpepper wrote:
>
> I re-read what I wrote and I realized that I didn't answer the question at all actually.. :)
>
> You can try to put a minus (-) between the % and I. I tried this in Linux and it works, but it did not work in Windows.
>
>
> Linux:
> >>> time.strftime("%a %b %d, %Y %-I:%M:%S %p",time.localtime(time.time()))
> 'Thu Mar 25, 2004 4:49:45 PM'
>
> Windows:
> >>> time.strftime("%a %b %d, %Y %-I:%M:%S %p",time.localtime(time.time()))
> 'Thu Mar 25, 2004 I:37:32 PM'
>
>
> Sorry about not paying attention the first time. :)
>
>
> -----Original Message-----
> From: tutor-bounces at python.org [mailto:tutor-bounces at python.org]On
> Behalf Of Eric Culpepper
> Sent: Thursday, March 25, 2004 4:24 PM
> To: tutor at python.org
> Subject: RE: [Tutor] Python time hour formatting
>
>
>
> Check the http://www.python.org/doc/current/lib/module-time.html document for the time module for all the different options for strftime.. but to directly answer your question you can use %H for 24 hour format, %I is for 12 hour format.
>
>
>
> -----Original Message-----
> From: tutor-bounces at python.org [mailto:tutor-bounces at python.org]On
> Behalf Of tpc at csua.berkeley.edu
> Sent: Thursday, March 25, 2004 4:15 PM
> To: tutor at python.org
> Subject: [Tutor] Python time hour formatting
>
>
>
>
> hi everyone, quick question. I currently have this:
>
> time.strftime("%a %b %d, %Y %I:%M:%S %p",time.localtime(time.time()))
>
> to print out:
>
> 'Thu Mar 25, 2004 02:19:23 PM'
>
> However, I don't want a leading zero in the hour column if
> there is only one digit. Is there a way to do this:
>
> 'Thu Mar 25, 2004 2:19:23 PM'
>
> ?
>
> I already tried '%1I' to no avail.
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list