I am trying to print the date in the following format using strftime: 06-03-2007 05:40PM
I have written the following code:
import time
print time.strftime("%m-%d-%Y %T:%M%p")
But it gives an error "Invalid format string". Why is that?
Maybe you are looking for hour
, H
instead of T
. check strftime possible options
print time.strftime("%m-%d-%Y %H:%M%p")
Note: The behavior is different on Windows and Linux machine. If you see what all are supported by Windows platform, check this http://msdn.microsoft.com/en-us/library/fe06s4ak.aspx
So it is better to use %H:%M:%S
than %T
on Windows.
The %T in:
print time.strftime("%m-%d-%Y %T:%M%p")
Does not exsist. You should use %H (0-23) or %I (0-11)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With