PYTHON学习0043:函数---time模块详解--2019-8-10
要使用time模块需先导入:
import time
1、time.time():打印当前时间戳
表示从1970年至今经过的秒速。
2、time.localtime(secs):将一个时间戳转换为当前时区的struct_time,secs为提供时,则以当前时间为准。
可在括号里加数字,则返回数字对应时间:
可以看到包含了很多变量,可以采用拼接形式表示时间了。比如:
先把time.time()赋值给变量a
3.time.gmtime():和localtime()方法类似,gmtime()方法是返回UTC时间,即格林威治时间,比北京时间晚8小时
4.time.mktime():将一个struct_time转化为时间戳:
5、time.sleep(secs):线程推迟指定的时间运行,单位为秒.
6、time.asctime():吧一个表示时间的元祖或者struct_time表示为这种形式:Sat Aug 10 14:54:25 2019。如果没有参入参数,则会将time.localtime()作为参数传入。
7、time.ctime(secs)吧一个时间戳(按秒计算的浮点数)转化为time.asctime()的形式,如果参数没有或者为None将会默认time.time为参数。它的作用相当于time.asctime(time.localtime(secs))。
8、time.strftime(format【,t】):吧一个代表时间的元祖或者struct_time(如由time.localtime()和time.gmtime())返回转化为个格式化的时间字符串,如果t未指定,将传入time.localtime()。
9、time.strptime(string【,format】)为time.strftime(format【,t】)的逆操作。
- Python time模块详解(常用函数实例讲解,非常好)
- Python学习笔记(三):Time、函数、模块、文件I/O、异常处理(快速入门篇)
- 【python】详解time模块功能asctime、localtime、mktime、sleep、strptime、strftime、time等函数以及时间的加减运算
- 【python】:python中time和calendar模块重要函数详解
- Python2.7 学习笔记 (二)—— 函数,模块,正则
- python time模块常用函数
- 【转】python time模块详解
- Python模块学习之os常用函数
- Python中time模块详解
- python语法学习之函数,类,模块
- Python3学习笔记05-字典、文件输入输出、模块、函数参数传递
- python time模块详解
- Python学习入门基础教程(learning Python)--2.3.2Python函数实参详解
- python 学习笔记 13 -- 常用的时间模块之time
- Python time模块详解
- Python模块学习 ---- time 日期时间处理
- python学习——python os.path模块常用方法详解
- python学习(2):函数、模块、类
- python语法学习之函数,类,模块