UTime



  • Utime.gmtime(secs) Convert a time expressed in seconds since the Epoch (see above) into an 8.
  • Utime.time ¶ Returns the number of seconds, as an integer, since the Epoch, assuming that underlying RTC is set and maintained as decsribed above. If an RTC is not set, this function returns number of seconds since a port-specific reference point in time (for embedded boards without a battery-backed RTC, usually since power up or reset).

Changes the access and modification times on each file of a list of files. The first two elements of the list must be the NUMERIC access and modification times, in that order. Returns the number of files successfully changed. The inode change time of each file is set to the current time. For example, this code has the same effect as the Unix touch(1) command when the files already exist and belong to the user running the program:

Since Perl 5.8.0, if the first two elements of the list are undef, the utime(2) syscall from your C library is called with a null second argument. On most systems, this will set the file's access and modification times to the current time (i.e., equivalent to the example above) and will work even on files you don't own provided you have write permission:

Thank you for using our U-Time product. This ’fullweb’ program allows the management of the most complex rosters, variable, fixed, open, night shift, overtime, absences, etc. It also allows to combine different clocking systems such as the card clocks, Biometric time clocks, clockings by smartphone or by PC with the IP address verification.

Zksoftware driver download for windows. Under NFS this will use the time of the NFS server, not the time of the local machine. If there is a time synchronization problem, the NFS server and local machine will have different times. The Unix touch(1) command will in fact normally use this form instead of the one shown in the first example.

Passing only one of the first two elements as undef is equivalent to passing a 0 and will not have the effect described when both are undef. This also triggers an uninitialized warning.

On systems that support futimes(2), you may pass filehandles among the files. On systems that don't support futimes(2), passing filehandles raises an exception. Filehandles must be passed as globs or glob references to be recognized; barewords are considered filenames.

Portability issues: 'utime' in perlport.

Firmware & API Reference > MicroPython Modules >utime

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

Time Epoch: Pycom’s ESP32 port uses standard for POSIX systems epoch of 1970-01-01 00:00:00 UTC.

Maintaining actual calendar date/time

This requires a Real Time Clock (RTC). On systems with underlying OS (including some RTOS), an RTC may be implicit. Setting and maintaining actual calendar time is responsibility of OS/RTOS and is done outside of MicroPython, it just uses OS API to query date/time. On baremetal ports however system time depends on machine.RTC() object. The current calendar time may be set using machine.RTC().datetime(tuple) function, and maintained by following means:

  • By a backup battery (which may be an additional, optional component for a particular board).
  • Using networked time protocol (requires setup by a port/user).
  • Set manually by a user on each power-up (many boards then maintain RTC time across hard resets, though some may require setting it again in such case).

If actual calendar time is not maintained with a system/MicroPython RTC, functions below which require reference to current absolute time may behave not as expected.

Methods

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, then the current time from the RTC is used.

  • 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.localtime([secs])

Like gmtime() but converts to local time. If secs is not provided, the current time from the RTC is used.

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 1970-01-01 00:00:00 UTC.

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)

Delay for given number of milliseconds, should be positive or 0.

utime.sleep_us(us)

Delay for given number of microseconds, should be positive or 0

utime.ticks_ms()

Time Zone Map

Returns uptime, in milliseconds.

utime.ticks_us()

Just like ticks_ms above, but in microseconds.

utime.ticks_cpu()

Same as ticks_us, but faster.

Times

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:

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])

Set or get the timezone offset, in seconds. If secs is not provided, it returns the current value.

Utime Gmod

UTime

In MicroPython, time.timezone works the opposite way to Python. In Python, to get the local time, you write local_time = utc - timezone, while in MicroPython it is local_time = utc + timezone.