在Python中,如何以可读格式显示当前时间 [英] In Python, how to display current time in readable format

查看:99
本文介绍了在Python中,如何以可读格式显示当前时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将当前时间显示为:

How can I display the current time as:

12:18PM EST on Oct 18, 2010

在Python中。谢谢。

in Python. Thanks.

推荐答案

首先是快速而肮脏的方式,第二个是精确的方式(识别日光的节省)。 >

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'

这篇关于在Python中,如何以可读格式显示当前时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆