zoukankan      html  css  js  c++  java
  • datetime中时间的formatter整理

    datetime是个很常用的模块,这个连python初学者都应该知道,datetime中有两个函数:strftime和strptime,里面都有个参数format,可以将输出的时间格式化。例如
    print datetime.datetime.now().strftime("%Y.%m.%d")
    就会显示类似2016.9.6这样的结果。但是百分号后面这些东西,这个我是真的记不住,每次都要百度查(桑心脸。所以特意从手册中把全部格式都整理出来,留作纪念。
    不对,留作以后忘了查询。
     

    Directive

    Meaning

    %a

    Locale’s abbreviated weekday name.

    缩写的星期几英文名称。

    %A

    Locale’s full weekday name.

    完整的星期几英文名称。

    %b

    Locale’s abbreviated month name.

    缩写的月份英文名称。

    %B

    Locale’s full month name.

    完整的月份英文名称。

    %c

    Locale’s appropriate date and time representation.

    一个适当的“日期+时间”表示法,我这里的结果是“月/日/年 时:分:秒”。

    %d

    Day of the month as a decimal number [01,31].

    现在日。

    %H

    Hour (24-hour clock) as a decimal number [00,23].

    现在小时(24小时制)。

    %I

    Hour (12-hour clock) as a decimal number [01,12].

    现在小时(12小时制)。

    %j

    Day of the year as a decimal number [001,366].

    现在是一年中的第几天。

    %m

    Month as a decimal number [01,12].

    现在月。

    %M

    Minute as a decimal number [00,59].

    现在分。

    %p

    Locale’s equivalent of either AM or PM.

    现在上/下午,用AM/PM表示。仅与%I一块使用。

    %S

    Second as a decimal number [00,61].

    现在秒。

    %U

    Week number of the year (Sunday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Sunday are considered to be in week 0.

    现在是一年中的第几个星期。从第一个星期日开始算第1个星期,之前算第0个。

    %w

    Weekday as a decimal number [0(Sunday),6].

    现在的星期数,星期日算0。

    %W

    Week number of the year (Monday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Monday are considered to be in week 0.

    现在是一年中的第几个星期。从第一个星期一开始算第1个星期,之前算第0个。

    %x

    Locale’s appropriate date representation.

    一个适当的“日期”表示法,我这里的结果是“月/日/年”。

    %X

    Locale’s appropriate time representation.

    一个适当的“时间”表示法,我这里的结果是“时:分:秒”。

    %y

    Year without century as a decimal number [00,99].

    现在年(后两位)。

    %Y

    Year with century as a decimal number.

    现在年(完整四位)。

    %Z

    Time zone name (no characters if no time zone exists).

    时区名称(如果没有时区则空白)。

    %%

    A literal '%' character.

    百分号的转义符。

    如果看不明白具体长什么样,可以用本文开头那条语句来测试。

    就酱。

    PS:博客园的表格好坑啊!and图没有什么用,但是如果不加的话,就给什么乱七八糟的东西打广告了。

  • 相关阅读:
    codeforces_Codeforces Round #541 (Div. 2)_abc
    小米 OJ 编程比赛 01 月常规赛_灯_找规律
    codeforces_A. Salem and Sticks_数组/暴力
    航班座位_hihocoder
    canvas
    你所必须知道的HTML
    表单及表单新增元素
    HTML5新增的结构元素
    jQuery菜单,导航与标签页
    JavaScript的DOM对象
  • 原文地址:https://www.cnblogs.com/anpengapple/p/5846368.html
Copyright © 2011-2022 走看看