zoukankan      html  css  js  c++  java
  • Python time和datetime模块

    time模块

    time() -- return current time in seconds since the Epoch as a float
    clock() -- return CPU time since process start as a float
    sleep() -- delay for a number of seconds given as a float
    gmtime() -- convert seconds since Epoch to UTC tuple
    localtime() -- convert seconds since Epoch to local time tuple
    asctime() -- convert time tuple to string
    ctime() -- convert time in seconds to string
    mktime() -- convert local time tuple to seconds since Epoch
    strftime() -- convert time tuple to string according to format specification
    strptime() -- parse string to time tuple according to format specification
    tzset() -- change the local timezone

    
    
    time() -- return current time in seconds since the Epoch as a float
    sleep() -- delay for a number of seconds given as a float

    print
    (time.time()) print (time.sleep(3)) print (time.time()) 结果: 1463616112.13201 None 1463616115.132182
    
    
    gmtime() -- convert seconds since Epoch to UTC tuple

    print
    (time.gmtime(1463616204.311283)) print (time.gmtime(time.time())) 结果: time.struct_time(tm_year=2016, tm_mon=5, tm_mday=19, tm_hour=0, tm_min=3, tm_sec=24, tm_wday=3, tm_yday=140, tm_isdst=0) time.struct_time(tm_year=2016, tm_mon=5, tm_mday=19, tm_hour=0, tm_min=4, tm_sec=15, tm_wday=3, tm_yday=140, tm_isdst=0)
    
    
    localtime() -- convert seconds since Epoch to local time tuple

    print
    (time.localtime()) print (time.localtime(1463616204.311283)) 结果: time.struct_time(tm_year=2016, tm_mon=5, tm_mday=19, tm_hour=8, tm_min=6, tm_sec=26, tm_wday=3, tm_yday=140, tm_isdst=0) time.struct_time(tm_year=2016, tm_mon=5, tm_mday=19, tm_hour=8, tm_min=3, tm_sec=24, tm_wday=3, tm_yday=140, tm_isdst=0)
    
    
    asctime() -- convert time tuple to string

    print
    (time.time()) print (time.asctime()) print (time.asctime(time.localtime(1463616204.311283))) 结果: 1463616842.655794 Thu May 19 08:14:02 2016 Thu May 19 08:03:24 2016
    def strftime(format, p_tuple=None):

    a = time.localtime(1363616204.311283) print (a) print (time.strftime('%Y%m%d',a)) 结果: time.struct_time(tm_year=2013, tm_mon=3, tm_mday=18, tm_hour=22, tm_min=16, tm_sec=44, tm_wday=0, tm_yday=77, tm_isdst=0) 20130318
    
    
    def strptime(string, format):

    print (time.strptime("20130318","%Y%m%d"))
    a = time.strptime("20130318","%Y%m%d")
    print (type(a))
    print (a.tm_mday)
    结果: 

      time.struct_time(tm_year=2013, tm_mon=3, tm_mday=18, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=0, tm_yday=77, tm_isdst=-1)
      <class 'time.struct_time'>
      18

     
    def mktime(p_tuple):
    print (time.gmtime())
    print (time.mktime(time.gmtime()))
    结果:
    time.struct_time(tm_year=2016, tm_mon=5, tm_mday=19, tm_hour=0, tm_min=47, tm_sec=21, tm_wday=3, tm_yday=140, tm_isdst=0)
    1463590041.0
  • 相关阅读:
    [ solr入门 ] 在schema.xml中加入自己的分词工具
    SQLServer2005获取大数据集时内存不足的解决办法[转]
    java位操作基本教程[转]
    log4j的最佳实践(转)
    [ lucene扩展 ] "Did you mean" feature with Apache Lucene SpellChecker
    java image filters[02]过滤器初探
    PHP serialize 和 JSON 解析与区别
    js 实现 静态缓存页面中访问动态IP下载地址
    smarty section foreach遍历多维数组
    【转】window.open 参数
  • 原文地址:https://www.cnblogs.com/python-study/p/5507448.html
Copyright © 2011-2022 走看看