孤独雪鹰 发表于 2018-8-16 12:14:57

Python时间模块 time 解读

Pythontime模块解读,陆续更新常用模块  
Epoch指的是一个特定的时间:1970-01-01 00:00:00 UTC。
  

  
1、time() -- return current time in seconds since the Epoch as a float
  
          以epoch作为浮点返回当前时间(以秒为单位)
  
time.time() --> 1477633880.74
  
2、clock() -- return CPU time since process start as a float
  
          返回进程开始或第一次调用clock()的CPU时间,这具有与系统一样的精度。
  

  
3、sleep(seconds) -- delay for a number of seconds given as a float
  
          延迟一定数量的秒作为浮点
  

  
4、gmtime(seconds=None) -- convert seconds since Epoch to UTC tuple
  
          将从Epoch开始的秒转换为UTC元组
  
time.gmtime() --> time.struct_time(tm_year=2016, tm_mon=10, tm_mday=28, tm_hour=5, tm_min=52, tm_sec=54, tm_wday=4, tm_yday=302, tm_isdst=0)
  

  
5、localtime(seconds=None) -- convert seconds since Epoch to local time tuple
  
          将从Epoch开始的秒转换为本地时间元组
  
time.localtime() --> time.struct_time(tm_year=2016, tm_mon=10, tm_mday=28, tm_hour=13, tm_min=53, tm_sec=31, tm_wday=4, tm_yday=302, tm_isdst=0)
  

  
6、asctime(p_tuple=None) -- convert time tuple to string
  
         将时间元组转换为字符串,例如 'Sat Jun 06 16:26:11 1998'。
  
   当时间元组不存在时,由localtime()返回的当前时间
  
   用来。
  
time.asctime() --> Fri Oct 28 13:54:28 2016
  

  
7、ctime(seconds=None) -- convert time in seconds to string
  
          将以秒为单位的时间转换为字符串,无参数,默认localetime()
  
time.asctime() --> Fri Oct 28 13:56:18 2016
  

  
8、mktime(p_tuple) -- convert local time tuple to seconds since Epoch
  
          将本地时间元组转换为自Epoch以来的秒数,需要参数
  
time.mktime(time.localtime()) --> 1477634240.0
  

  
9、strftime(format, p_tuple=None) -- convert time tuple to string according to format specification
  
          根据格式规范将时间元组转换为字符串
  
time.strftime("%Y-%m-%d %X %a",time.localtime()) --> 2016-10-28 14:00:07 Fri
  

  
10、strptime(string, format) -- parse string to time tuple according to format specification
  
          根据格式规范将字符串转换为时间元组


页: [1]
查看完整版本: Python时间模块 time 解读