问题
How do I format a date in python to look like this: weekday:month:day(number):HH:MM:SS(military):EST/CST/PST:YYYY
? I am familiar with strftime(), but I am unsure how I would handle the HH:MM:SS and EST/CST/PST.
example of how I am trying to get the date to look:
Sun Mar 10 15:53:00 EST 2013
回答1:
Use strftime
to output a formatted string representation:
print time.strftime("%a %b %d %H:%M:%S %Z %Y")
A list of the format codes can be found here
回答2:
from time import gmtime, strftime
print strftime("%a %b %d %H:%M:%S %Z %Y", gmtime())
This will produce
Fri Mar 22 21:10:56 Eastern Standard Time 2013
You'll have to settle for the long name of the timezone unless you want to use pytz. I suppose it's worth noting that timezone abbreviations aren't unique.
来源:https://stackoverflow.com/questions/15579599/date-format-with-timezone