码迷,mamicode.com
首页 > 编程语言 > 详细

Python的time模块

时间:2017-04-17 00:37:24      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:cal   hang   数组   sleep   格式   mkt   print   oca   number   

time模块下只有若干个方法,没有类,所以直接用time.方法即可

1.time() -- return current time in seconds since the Epoch as a float
  print time.time() 返回日期的秒数 1492351508.72

2.clock() -- return CPU time since process start as a float
  输出CPU时间
3.sleep() -- delay for a number of seconds given as a float

4.gmtime() -- convert seconds since Epoch to UTC tuple
5.localtime() -- convert seconds since Epoch to local time tuple
  把时间戳转为time.time_struct格式的时间数组
  print time.localtime(time.time())
  time.struct_time(tm_year=2017, tm_mon=4, tm_mday=16, tm_hour=22, tm_min=14, tm_sec=57, tm_wday=6, tm_yday=106, tm_isdst=0)

6.asctime() -- convert time tuple to string
  把时间数组转换为字符串
  print time.asctime(time.localtime(time.time()))
  Sun Apr 16 22:27:11 2017
7.ctime() -- convert time in seconds to string
  把以秒表示的时间转为字符串
  print time.ctime(time.time())
  Sun Apr 16 22:27:57 2017
8.mktime() -- convert local time tuple to seconds since Epoch
  把时间数组转为秒表示
  print time.mktime(time.localtime(time.time()))
  1492352997.0
9.strftime() -- convert time tuple to string according to format specification
10.strptime() -- parse string to time tuple according to format specification
11.tzset() -- change the local timezone

Python的time模块

标签:cal   hang   数组   sleep   格式   mkt   print   oca   number   

原文地址:http://www.cnblogs.com/cindy-cindy/p/6720392.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!