【Python】日期时间格式化输出

要格式化日期,需要先导入time包:

import time

格式化时间使用time.strftime()方法,该方法的接口文档如下:

def strftime(format, p_tuple=None): # real signature unknown; restored from __doc__
    """
    strftime(format[, tuple]) -> string
    
    Convert a time tuple to a string according to a format specification.
    See the library reference manual for formatting codes. When the time tuple
    is not present, current time as returned by localtime() is used.
    
    Commonly used format codes:
    
    %Y  四位数的年份表示(000-9999)
    %m  月份(01-12)
	%d  月内中的一天(0-31)
	%H  24小时制小时数(0-23)
	%I  12小时制小时数(01-12).
    %M  分钟数 [00,59].
    %S  秒数 [00,61].
    %z  Time zone offset from UTC. 与UTC的时区偏移量
    %a  本地简化星期名称
	%A  本地完整星期名称
	%b  本地简化的月份名称
	%B  本地完整的月份名称
    %c  本地相应的日期表示和时间表示
    %p  本地A.M.或P.M.的等价符.
    
    Other codes may be available on your p
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值