Skip to content

Clocktime

Overview

The time module provides data such as the current time and time zone offset, reducing the complexity of developers in time-related development.

Time Module

clocktime.now()

  • Description: This attribute represents the real-time timestamp (in seconds).
  • Return Value: When the time has not been synchronized, -1 is returned; otherwise, the timestamp is returned.

clocktime.datetime()

  • Description: This attribute represents the real-time date.
  • Return Value: The returned format is (YYYY, MM, DD, hh, mm, ss, wday, yday).

clocktime.tzoffset()

  • Description: This attribute indicates the amount of time (in seconds) offset by the current time compared to the UTC+0 time zone.

Usage examples

import clocktime

# Get real-time timestamp
curr_time = clocktime.now()

# Get real-time date
curr_date = clocktime.datetime()

# Get the time zone offset
tz = clocktime.tzoffset()

Precautions

  • If you want to get the running time of the device from startup to present, you can use the time module provided in MicroPython.