Skip to content
Boris Lovosevic edited this page Jan 25, 2019 · 5 revisions

utime Module



The utime module provides functions for getting the current time and date, measuring time intervals, and for delays.

Time Epoch: This port uses standard for POSIX systems epoch of 1970-01-01 00:00:00 UTC.

Maintaining actual calendar date/time: K210 RTC peripheral is used for maintaining the acctual date/time.
The date/time information is lost after power is removed.
Support for external RTC module is planned for some later time.


## Methods

utime.localtime( [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.
The time returnes is corrected to the local time zone.

  • year includes the century (for example 2014).
  • month is 1-12
  • mday is 1-31
  • hour is 0-23
  • minute is 0-59
  • second is 0-59
  • weekday is 0-6 for Mon-Sun
  • yearday is 1-366

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.
The time returned is the UTC+0 time.

  • year includes the century (for example 2014).
  • month is 1-12
  • mday is 1-31
  • hour is 0-23
  • minute is 0-59
  • second is 0-59
  • weekday is 0-6 for Mon-Sun
  • yearday is 1-366

utime.mktime( time_tuple [,tz] [,setrtc] )

This is inverse function of gmtime/localtime. It’s argument is a full 8-tuple which expresses a time as per gmtime/localtime. It returns an integer which is the number of seconds since Epoch (Jan 1, 1970).

If the optional argument tz is provides, the local time zone is set.
The tz argument must be a time zone string, for example "CET-1CEST,M3.5.0,M10.5.0/3".

If the optional argument setrtc is True, the system RTC time is set.

utime.strftime( format [,time] [,local] )

Convert a tuple time representing a time as returned by gmtime() or localtime() to a string as specified by the format argument. If time is not provided, the current RTC time is used.
format must be a string. Standard Python time formating should be used
If local argument is True (default), local time is used, if False gmtime is used.

utime.sleep( seconds )

Sleep for the given number of seconds.
Seconds provided as integer or a floating-point (sleep for a fractional number of seconds) are accepted.

utime.sleep_ms( ms )

Sleep for the given number of milli seconds.

utime.sleep_us( us )

Sleep for the given number of micro seconds.

Clone this wiki locally