Python中的time包
time包基于C语言的库函数(libraryfunctions)。Python的解释器通常是用C编写的,Python的一些函数也会直接调用C语言的库函数。
importtime
print(time.time())#wallclocktime,unit:second
print(time.clock())#processorclocktime,unit:second
time.sleep()可以将程序置于休眠状态,直到某时间间隔之后再唤醒程序,让程序继续运行。
importtime
print('start')
time.sleep(10)#sleepfor10seconds
print('wakeup')
当我们需要定时地查看程序运行状态时,就可以利用该方法。
time包还定义了struct_time对象。该对象实际上是将挂钟时间转换为年、月、日、时、分、秒……等日期信息,存储在该对象的各个属性中(tm_year,tm_mon,tm_mday...)。下面方法可以将挂钟时间转换为struct_time对象:
st=time.gmtime()#返回struct_time格式的UTC时间
st=time.localtime()#返回struct_time格式的当地时间,当地时区根据系统环境决定。
s=time.mktime(st)#将struct_time格式转换成wallclocktime
以上内容为大家介绍了Python中的time包,希望对大家有所帮助,如果想要了解更多Python相关知识,请关注IT培训机构:千锋教育。

相关推荐HOT
更多>>
python怎么输入多变量
Python同时输入多个值 1.同时输入多个字符串,字符串间以逗号/空...详情>>
2023-11-12 23:43:43
python岗位主要做什么工作?
python的工作岗位还是很多的,涉及的工作方向也很广,下面举一些常见的岗位,大家可以参考:Web应用开发Python经常被用于Web开发。例如,通过mo...详情>>
2023-11-12 23:05:27
python能做网站吗?
python可以做网站,Python有很多优秀的网站框架,可以非常快速的建一个网站。比如django之类的框架。Django、TurboGears、Eurasia、UliWeb等:...详情>>
2023-11-12 21:47:07
python中的int是什么意思?
python中的int()函数用于将一个字符串或数字转换为整型。语法以下是int()方法的语法:classint(x,base=10)参数x--字符串或数字。base--进制数,...详情>>
2023-11-12 21:21:30