python 3 中的time模块使用(待完善)
2017-12-08 21:22
330 查看
python中和时间处理有关的模块包括time,datetime,calender等模块:
python通常用这几种方式来表示时间:1)时间戳,2)格式化的字符串,3)元祖struct_time中含有九个元素,分别表示的就是年月日等信息time模块中包含的某些函数:
time.localtime([secs]): 将一个时间戳转换为当前时区的struct_time。secs参数未提供,则以当前时间为准。
time.gmtime([secs]): 和localtime()方法类似,gmtime()方法是将一个时间戳转换为UTC时区(0时区)的struct_time。
time.time():返回当前时间的时间戳。
time.mktime(t):将一个struct_time转化为时间戳。
time.sleep(secs):线程推迟指定的时间运行。单位为秒。
time.clock():第一次运行的时候表示程序运行到现在所用的时间,以后每次调用的话就是指第一次调用之后到现在的所用的运行时间
time.asctime([t]):把一个表示时间的元组或者struct_time表示为这种形式:'Sun Jun 20 23:21:05 1993'。如果没有参数,将会将time.localtime()作为参数传入。
time.ctime([secs]):把一个时间戳(按秒计算的浮点数)转化为time.asctime()的形式。如果参数未给或者为None的时候,将会默认time.time()为参数。它的作用相当于time.asctime(time.localtime(secs))。
time.strftime(format[, t]):把一个代表时间的元组或者struct_time(如由time.localtime()和time.gmtime()返回)转化为格式化的时间字符串。如果t未指定,将传入time.localtime(),如果元组中任何一个元素越界,ValueError的错误将会被抛出。
time.strptime(string[, format]):把一个格式化时间字符串转化为struct_time。实际上它和strftime()是逆操作。
相关文章推荐
- python的time模块使用
- Python time、datetime、os、random、sys、hashlib、json、shutil、logging、paramiko、subprocess、ConfigParser、xml、shelve模块的使用
- Python时间模块datetime、time、calendar的使用方法
- python time datetime模块使用方法记录
- Python中time,datetime模块的常见使用方法
- python的time模块使用
- python中time和random模块的使用
- 使用Python的timeit模块
- python time模块使用实例
- python timeit模块的使用(附加append、insert、extend用法)
- Python下time模块和datetime模块的使用
- python中使用time模块计算代码执行效率的精度测试
- 初学python:calendar和time模块的简单使用
- python time模块使用笔记(更新)
- python中使用time模块计算代码执行效率的精度测试(转)
- Python时间模块datetime、time、calendar的使用方法
- Python中time模块的使用
- python的time模块使用
- python 学习笔记 13 -- 经常使用的时间模块之time
- python的time模块使用