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
  • 相关阅读:
    分享一个自己写的vue多语言插件smart-vue-i18n
    利用vw+rem实现移动web适配布局
    你说前端不了解业务?
    小程序开发总结一:mpvue框架及与小程序原生的混搭开发
    小码农的职场人生一:由张小平离职引发的一些吐槽
    javascript本地缓存方案-- 存储对象和设置过期时间
    手淘移动适配方案flexible.js兼容bug处理
    微信小程序入坑之自定义组件
    vuejs开发组件分享之H5图片上传、压缩及拍照旋转的问题处理
    非域环境下使用证书部署数据库(SqlServer2008R2)镜像
  • 原文地址:https://www.cnblogs.com/python-study/p/5507448.html
Copyright © 2011-2022 走看看