fixed utime api

This commit is contained in:
gijsio
2021-01-11 13:25:37 +01:00
committed by peter-pycom
parent 540bc961bd
commit c970967b82

View File

@@ -22,9 +22,9 @@ If actual calendar time is not maintained with a system/MicroPython RTC, functio
## Methods
#### utime.gmtime(\[secs\])
### utime.gmtime([secs])
Convert a time expressed in seconds since the Epoch (see above) into an 8-tuple which contains: `(year, month, mday, hour, minute, second, weekday, yearday)` If `secs` is not provided or `None`, then the current time from the RTC is used.
Convert a time expressed in seconds since the Epoch (see above) into an 8-tuple which contains: `(year, month, mday, hour, minute, second, weekday, yearday)` If `secs` is not provided, then the current time from the RTC is used.
* `year` includes the century (for example 2014).
* `month` is 1-12
@@ -35,39 +35,39 @@ Convert a time expressed in seconds since the Epoch (see above) into an 8-tuple
* `weekday` is 0-6 for Mon-Sun
* `yearday` is 1-366
#### utime.localtime(\[secs\])
### utime.localtime([secs])
Like `gmtime()` but converts to local time. If `secs` is not provided or `None`, the current time from the RTC is used.
Like `gmtime()` but converts to local time. If `secs` is not provided, the current time from the RTC is used.
#### utime.mktime()
### utime.mktime(time)
This is inverse function of `localtime`. It's argument is a full 8-tuple which expresses a time as per `localtime`. It returns an integer which is the number of seconds since `Jan 1, 2000`.
This is inverse function of `localtime`. It's argument is a full 8-tuple which expresses a time as per `localtime`. It returns an integer which is the number of seconds since `1970-01-01 00:00:00 UTC`.
#### utime.sleep(seconds)
### utime.sleep(seconds)
Sleep for the given number of `seconds`. `seconds` can be a floating-point number to sleep for a fractional number of seconds. Note that other MicroPython ports may not accept floating-point argument, for compatibility with them use `sleep_ms()` and `sleep_us()` functions.
#### utime.sleep\_ms(ms)
### utime.sleep_ms(ms)
Delay for given number of milliseconds, should be positive or 0.
#### utime.sleep\_us(us)
### utime.sleep_us(us)
Delay for given number of microseconds, should be positive or 0
#### utime.ticks\_ms()
### utime.ticks_ms()
Returns uptime, in milliseconds.
#### utime.ticks\_us()
### utime.ticks_us()
Just like `ticks_ms` above, but in microseconds.
#### utime.ticks\_cpu()
### utime.ticks_cpu()
Same as `ticks_us`, but faster.
#### utime.ticks\_diff(new, old)
### utime.ticks_diff(new, old)
Measure period between consecutive calls to `ticks_ms()`, `ticks_us()`, or `ticks_cpu()`. The value returned by these functions may wrap around at any time, so directly subtracting them is not supported. `ticks_diff()` should be used instead. "old" value should actually precede "new" value in time, or result is undefined. This function should not be used to measure arbitrarily long periods of time (because `ticks_*()` functions wrap around and usually would have short period). The expected usage pattern is implementing event polling with timeout:
@@ -80,15 +80,15 @@ while pin.value() == 0:
raise TimeoutError
```
#### utime.time()
### utime.time()
Returns the number of seconds, as an integer, since the Epoch, assuming that underlying RTC is set. If an RTC is not set, this function returns number of seconds since power up or reset). If you want to develop portable MicroPython application, you should not rely on this function to provide higher than second precision. If you need higher precision, use `ticks_ms()` and `ticks_us()` functions, if you need calendar time, `localtime()` without an argument is a better choice.
#### utime.timezone(\[secs\])
### utime.timezone([secs])
Set or get the timezone offset, in seconds. If `secs` is not provided, it returns the current value.
{{% hint style="info" %}}
In MicroPython, `time.timezone` works the opposite way to Python. In [Python](https://docs.python.org/3/library/time.html#time.timezone), to get the local time, you write `local_time = utc - timezone`, while in MicroPython it is `local_time = utc + timezone`.
{{% /hint %}}
> In MicroPython, `time.timezone` works the opposite way to Python. In [Python](https://docs.python.org/3/library/time.html#time.timezone), to get the local time, you write `local_time = utc - timezone`, while in MicroPython it is `local_time = utc + timezone`.