当前第2页 返回上一页
%p 以 A.M./P.M.方式显示是上午还是下午
1 2 3 4 | >>> import datetime
>>> now = datetime.datetime.now()
>>> now.strftime( '%p' )
'PM'
|
%S 显示0-59之间的秒数
1 2 3 4 | >>> import datetime
>>> now = datetime.datetime.now()
>>> now.strftime( '%S' )
'29'
|
%U 显示一年中的第几周,星期天为一周的第一天,例如当前www.jb51.net服务器时间为2013年9月15日,星期天,显示为第37周
1 2 3 4 | >>> import datetime
>>> now = datetime.datetime.now()
>>> now.strftime( '%U' )
'37'
|
%w 显示一周中的第几天,其中星期天为0,星期一为1,例如:jb51.net当前日期为2013年9月17日星期二,则显示结果为2
1 2 3 4 | >>> import datetime
>>> now = datetime.datetime.now()
>>> now.strftime( '%w' )
'2'
|
%W 显示一年中的第几周,和U%把不同的是星期一为一周的第一天,例如当前www.jb51.net服务器时间为2013年9月17日,星期二,显示为第37周,范围在0-51之间
1 2 3 4 | >>> import datetime
>>> now = datetime.datetime.now()
>>> now.strftime( '%W' )
'37'
|
%x 显示当地的日期,例如jb51.net本地时间为:北京时间2013年9月17日
1 2 3 4 | >>> import datetime
>>> now = datetime.datetime.now()
>>> now.strftime( '%x' )
'09/17/13'
|
%X 显示当地的时间,例如jb51.net本地时间为:北京时间2013年9月17日 07:55:04
1 2 3 4 | >>> import datetime
>>> now = datetime.datetime.now()
>>> now.strftime( '%X' )
'07:55:04'
|
%y 显示(00 - 99) 之间的年份,例如:jb51.net服务器时间为:2013年9月17日,则显示结果为13
1 2 3 4 | >>> import datetime
>>> now = datetime.datetime.now()
>>> now.strftime( '%y' )
'13'
|
%Y 显示完整年份,例如:jb51.net服务器时间为:2013年9月17日,则显示结果为2013
1 2 3 4 | >>> import datetime
>>> now = datetime.datetime.now()
>>> now.strftime( '%Y' )
'2013'
|
%z, %Z 输出时区,如果不能显示,则显示为空字符 %% 用于显示%符号
1 2 | >>> now.strftime( '%%' )
'%'
|
在举一个完整的例子:
显示当前日期时间:格式为:年-月-日 时:分:秒
1 2 | >>> datetime.datetime.now().strftime( '%Y-%m-%d %H:%M:%S' );
'2013-09-17 08:06:17'
|
以上就是python中日期和时间格式化输出的方法小结_python的详细内容,更多文章请关注木庄网络博客!!
返回前面的内容
相关阅读 >>
Python如何删除列表一个元素
Python中可以使用两种方法实现更新数据库脚本的示例
为什么用Python写网页
Python global用法有哪些?
Python中的栈指的是什么
Python list是否包含另一个list所有元素
Python中线程同步原语的代码示例
什么是Python的注释符
对Python的链表数据结构讲解
Python中strip什么意思
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python中日期和时间格式化输出的方法小结_python