zoukankan      html  css  js  c++  java
  • python time format

    指令

    含义

    示例

    注释

    %a

    当地工作日的缩写。

    Sun, Mon, …, Sat (美国);
    So, Mo, …, Sa (德国)

    (1)

    %A

    当地工作日的全名。

    Sunday, Monday, …, Saturday (美国);
    Sonntag, Montag, …, Samstag (德国)

    (1)

    %w

    以十进制数显示的工作日,其中0表示星期日,6表示星期六。

    0, 1, …, 6

     

    %d

    补零后,以十进制数显示的月份中的一天。

    01, 02, …, 31

     

    %b

    当地月份的缩写。

    Jan, Feb, …, Dec (美国);
    Jan, Feb, …, Dez (德国)

    (1)

    %B

    当地月份的全名。

    January, February, …, December (美国);
    Januar, Februar, …, Dezember (德国)

    (1)

    %m

    补零后,以十进制数显示的月份。

    01, 02, …, 12

     

    %y

    补零后,以十进制数表示的,不带世纪的年份。

    00, 01, …, 99

     

    %Y

    十进制数表示的带世纪的年份。

    1970, 1988, 2001, 2013

     

    %H

    以补零后的十进制数表示的小时(24 小时制)。

    00, 01, …, 23

     

    %I

    以补零后的十进制数表示的小时(12 小时制)。

    01, 02, …, 12

     

    %p

    本地化的 AM 或 PM 。

    AM, PM (美国);
    am, pm (德国)

    (1), (2)

    %M

    补零后,以十进制数显示的分钟。

    00, 01, …, 59

     

    %S

    补零后,以十进制数显示的秒。

    00, 01, …, 59

    (3)

    %f

    以十进制数表示的微秒,在左侧补零。

    000000, 000001, …, 999999

    (4)

    %z

    UTC offset in the form +HHMM or -HHMM (empty string if the the object is naive).

    (empty), +0000, -0400, +1030

    (5)

    %Z

    时区名称(如果对象为简单型则为空字符串)。

    (空), UTC, EST, CST

     

    %j

    以补零后的十进制数表示的一年中的日序号。

    001, 002, …, 366

     

    %U

    以补零后的十进制数表示的一年中的周序号(星期日作为每周的第一天)。 在新的一年中第一个星期日之前的所有日子都被视为是在第 0 周。

    00, 01, …, 53

    (6)

    %W

    以十进制数表示的一年中的周序号(星期一作为每周的第一天)。 在新的一年中第一个第期一之前的所有日子都被视为是在第 0 周。

    00, 01, …, 53

    (6)

    %c

    本地化的适当日期和时间表示。

    Tue Aug 16 21:30:00 1988 (美国);
    Di 16 Aug 21:30:00 1988 (德国)

    (1)

    %x

    本地化的适当日期表示。

    08/16/88 (None);
    08/16/1988 (en_US);
    16.08.1988 (de_DE)

    (1)

    %X

    本地化的适当时间表示。

    21:30:00 (en_US);
    21:30:00 (de_DE)

    (1)

    %%

    字面的 '%' 字符。

    %

    python code:

    import datetime,time
    class MyDate():
        @staticmethod
        def now_format(format='%Y-%m-%d %H:%M:%S'):
            return datetime.datetime.now().strftime(format)
        @staticmethod
        def str2timestamp(timestr,format='%Y-%m-%d %H:%M:%S'):
            '''
            指定日期格式,转换成时间戳
            '''
            return int(time.mktime(time.strptime(timestr, format)))
        @staticmethod
        def timestamp2str(timestamp,format='%Y-%m-%d %H:%M:%S'):
            '''
            指定时间戳,转换成日期格式
            '''
            return time.strftime(format, time.localtime(timestamp))
        @staticmethod
        def str2str(timestr,format1='%Y-%m-%d %H:%M:%S',format2='%Y-%m-%d %H:%M:%S'):
            return MyDate.timestamp2str( MyDate.str2timestamp(timestr,format1),format2)
    #示例
    print(MyDate.str2str("Thu Aug 23 19:45:07 +0000 2012","%a %b %d %H:%M:%S %z %Y"))

    拿走不谢

  • 相关阅读:
    AX 2012 Form and Parts
    AX 2012 SSRS print setting-报表打印输出设置
    AX 2012 关于parts 添加
    AX Dynamic 2012 tabletype:TempDB使用
    AX Dynamic 2012 SSRS 按行数分页
    AX Dynamic 2012 SSRS autorepot中取当前公司名、打印时间、打印页码
    AX Dynamics 去中文字符长度:中文字符当2个字符处理
    AX dynamics 2012 ssrs 开发报错:Native compiler return value: ‘[BC30179]
    在Ubuntu 下编译c语言
    在ubuntu加载flash的方法
  • 原文地址:https://www.cnblogs.com/xunhanliu/p/14005947.html
Copyright © 2011-2022 走看看