python学习之time篇

        time 库
        import time
        
        时间获取
        time.time()--------------------------------------------------------------------------------------------#获取的浮点数
        time.ctime()-------------------------------------------------------------------------------------------#可理解时间
        time.gmtime()-----------------------------------------------------------------------------------------#计算机可理解的时间
        
        时间格式化
        time.strftime(tpl,ts)-------------------------------------------------------------------------------------#tpl 是格式化模板字符串,用来定义输出结果 ts是计算机内部的时间类型变量
        例如:
            
>>>t=time.gmtime()
>>>time.strftime("%Y-%m-%d:%H:%M:%S:%p:%B:%a")            #输出年月日,时分秒  %B 月份名称 %b 月份名称缩写  %A 星期 %a 星期缩写  %p 上下午
  
        #'2018-06-30:16:45:40:PM:June:Sat'
        


        时间计时
        time.sleep(s)----------------------------------------------------------------------------------------# s 为休眠时间        <产生时间>
        time.perf_counter()-------------------------------------------------------------------------------------#获取cpu级别的时间     <测量时间>
        例如:
            >>>start = perf_counter()
            >>>end = perf_counter()
            >>>duration=end - start                        #持续时间


猜你喜欢

转载自blog.csdn.net/qq_25233621/article/details/80978334