In Python, how to display current time in readable format

后端 未结 6 1189
感情败类
感情败类 2020-12-07 18:15

How can I display the current time as:

12:18PM EST on Oct 18, 2010

in Python. Thanks.

6条回答
  •  抹茶落季
    2020-12-07 19:02

    First the quick and dirty way, and second the precise way (recognizing daylight's savings or not).

    import time
    time.ctime() # 'Mon Oct 18 13:35:29 2010'
    time.strftime('%l:%M%p %Z on %b %d, %Y') # ' 1:36PM EDT on Oct 18, 2010'
    time.strftime('%l:%M%p %z on %b %d, %Y') # ' 1:36PM EST on Oct 18, 2010'
    

提交回复
热议问题