zoukankan      html  css  js  c++  java
  • Python学习之路(十二):基础知识之time模块

    1.三种时间类型

     import time
    1
    # 格式化时间:2020-02-20

    2 # 1970 1 1 0:0:0 3 4 # 以秒位单位,称为时间戳时间 5 print(time.time()) 6 # 结果:1582605479.913204 7 8 # 字符串时间 9 print(time.strftime('%Y-%m-%d %H:%M:%S')) 10 print(time.strftime('%c')) 11 # 结果:2020-02-25 12:39:08 12 Tue Feb 25 12:39:08 2020 13 14 # 结构化时间(元组时间) 15 struct_time = time.localtime() 16 print(struct_time) 17 # 结果:time.struct_time(tm_year=2020, tm_mon=2, tm_mday=25, tm_hour=12, tm_min=40, tm_sec=24, tm_wday=1, tm_yday=56, tm_isdst=0) 18 print(struct_time.tm_mon) 19 # 结果:2

    2.时间格式之间的转换

    结构化时间起承上启下的作用。

    import time
    1
    # 1.时间戳时间-->结构化时间 2 print(time.time()) 3 struct_time = time.localtime(1500000000) 4 print(struct_time)
    import time
    1
    # 2.时间戳时间-->字符串时间 2 print(time.time()) 3 struct_time = time.localtime(1500000000) 4 ret = time.strftime('%y/%m/%d %H:%M:%S', struct_time) 5 print(ret)
    import time
    1
    # 字符串时间-->时间戳时间 2 3 struct_time = time.strptime('2018-8-8', '%Y-%m-%d') 4 print(struct_time) 5 res = time.mktime(struct_time) 6 print(res)
  • 相关阅读:
    老天待我不薄,又来这么一题POJ1753
    HDOJ4857【拓扑排序】
    二分匹配ZOJ3646
    poj3185//BFS随便切...
    poj2239 poj1274【二分匹配】
    每天一水poj1502【最短路】
    POJ1466/HDOJ1068 谈谈二分匹配的时间复杂度
    纯拓扑排序一搞poj2367
    poj1477(水)
    用动态链表high-poj 1528
  • 原文地址:https://www.cnblogs.com/Studying-Du/p/12361139.html
Copyright © 2011-2022 走看看