zoukankan      html  css  js  c++  java
  • python之time模块

    time获取时间戳:

    import time
    print(time.time())
    
    E:python36python3.exe E:/pj/test/test.py
    1520243808.7411149
    

    localtime获取当前时间对象,然后再去获取年月日时分秒的属性:

    import time
    a=time.localtime()
    print (a)
    print (a.tm_year)
    print (a.tm_mon)
    print (a.tm_mday)
    print (a.tm_hour)
    print (a.tm_min)
    print (a.tm_sec)
    
    E:python36python3.exe E:/pj/test/test.py
    time.struct_time(tm_year=2018, tm_mon=3, tm_mday=5, tm_hour=18, tm_min=4, tm_sec=43, tm_wday=0, tm_yday=64, tm_isdst=0)
    2018
    3
    5
    18
    4
    43

    asctime获取当前时间的标准格式:

    import time
    print(time.asctime(time.localtime()))
    
    E:python36python3.exe E:/pj/test/test.py
    Mon Mar  5 18:07:09 2018

    strftime当前时间的格式化输出:

    import time
    print (time.strftime('%Y-%m-%d %H:%M:%S',time.localtime()))
    print(time.strftime('%a %b %d %H:%M:%S %Y',time.localtime()))
    
    E:python36python3.exe E:/pj/test/test.py
    2018-03-05 18:08:58
    Mon Mar 05 18:08:58 2018

    strptime和mktime时间格式化转时间戳:

    import time
    a=time.strftime('%a %b %d %H:%M:%S %Y',time.localtime())
    print (a)
    print (time.mktime(time.strptime(a,"%a %b %d %H:%M:%S %Y")))
    
    E:python36python3.exe E:/pj/test/test.py
    Mon Mar 05 18:11:10 2018
    1520244670.0
    

      

  • 相关阅读:
    jq function return value
    danci4
    danci3
    danci2
    项目总结 和语言总结。
    vm 安装 ox 10.13
    ios 异步和多线程
    ios 语法问题 全局变量。
    mvc
    object-c 之autolayout
  • 原文地址:https://www.cnblogs.com/letmeiscool/p/8510503.html
Copyright © 2011-2022 走看看