2013-03-22 189 views
2

如何在python中格式化日期如下所示:weekday:month:day(number):HH:MM:SS(military):EST/CST/PST:YYYY?我熟悉strftime(),但我不确定如何处理HH:MM:SS和EST/CST/PST。带时区的日期格式

的,我怎么想获取日期看

例如:

Sun Mar 10 15:53:00 EST 2013 

回答

2

使用strftime输出格式化字符串表示:

print time.strftime("%a %b %d %H:%M:%S %Z %Y") 

格式代码的列表可以发现here

2
from time import gmtime, strftime 
print strftime("%a %b %d %H:%M:%S %Z %Y", gmtime()) 

这会产生

周五3月22日21点10分56秒美国东部标准时间2013

,除非你想用pytz你必须要解决的时区的长名。我想这值得注意,timezone abbreviations aren't unique