utime.localtime([secs])
参数 | 类型 | 必选参数? | 说明 |
---|---|---|---|
secs | int | 否 | 要转换的秒数 |
(year, month, mday, hour, minute, second, weekday, yearday)
year
:年份,int型
month
:月份,1~12,int型
mday
:日,当月几号,1~31,int型
hour
:小时,0~23,int型
minute
:分钟,0~59,int型
second
:秒,0~59,int型
weekday
:星期几,周一到周日是0~6,int型
yearday
:一年中的第多少天,int型
示例:
>>> utime.localtime()
(2021, 11, 22, 16, 52, 34, 0, 326)
>>> utime.localtime(138930193)
(2004, 5, 26, 23, 43, 13, 2, 147)
utime.mktime(date)
函数功能:
该函数作用与locatime()相反,它将一个存放在元组中的时间转换为以秒计的时间戳。
参数说明:
参数 | 类型 | 必选参数? | 说明 |
---|---|---|---|
secs | int | 否 | 要转换的秒数 |
返回值:
返回date对应的秒数
示例:
>>> date = (2021, 11, 2, 14, 54, 42, 1, 0)
>>> utime.mktime(date)
689180082
utime.sleep(seconds)
参数 | 类型 | 必选参数? | 说明 |
---|---|---|---|
seconds | int | 是 | 休眠的目标秒数 |
注意:调用sleep()会导致程序处于阻塞状态。
utime.sleep_ms(ms)
参数 | 类型 | 必选参数? | 说明 |
---|---|---|---|
ms | int | 是 | 休眠的目标毫秒数 |
注意:调用sleep_ms()会导致程序处于阻塞状态。
utime.sleep_us(us)
参数 | 类型 | 必选参数? | 说明 |
---|---|---|---|
us | int | 是 | 休眠的目标微妙数 |
注意:调用sleep_us()会导致程序处于阻塞状态。
utime.ticks_ms()
ticks_diff()
函数中。utime.ticks_us()
和ticks_ms()
类似,只是返回微秒计数器。
utime.ticks_cpu()
utime.ticks_diff(new_ticks, early_ticks)
函数功能:
计算两次调用 ticks_ms()
, ticks_us()
,或 ticks_cpu()
之间的时间差。因为这些函数的计数值可能会回环,不能直接相减,需要使用 ticks_diff() 函数。early_ticks时间需要在new_ticks时间之前,否则结果无法确定。这个函数不能计算很长的时间的差值(因为 ticks_*()函数会回绕,回绕周期一般不长)。通常用法是在带超时的轮询事件中调用。
示例:
cnt = 0
t1 = utime.ticks_us()
while (utime.ticks_diff(utime.ticks_us(), t1) < 100):
cnt += 1
utime.time()
ticks_ms()
和ticks_us()
函数,如果需要日历时间,则直接调用localtime()
。此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。