Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

date format with timezone

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
like image 997
WorkerBee Avatar asked May 08 '26 15:05

WorkerBee


1 Answers

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.

like image 122
John Avatar answered May 11 '26 05:05

John



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!