maix.time
maix.time module
You can use
maix.time
to access this module with MaixPy
This module is generated from MaixPy and MaixCDK
1. Module#
No module
2. Enum#
3. Variable#
4. Function#
4.1. time#
Get current time in s
item | description |
---|---|
return | current time in s, double type |
attention | If board have no RTC battery, when bootup and connect to network, system will automatically sync time by NTP, will cause time() have big change, e.g. before NTP: 10(s), after: 1718590639.5149617(s). If you want to calculate time interval, please use ticks_s(). |
C++ defination code:
4.2. time_ms#
Get current time in ms
item | description |
---|---|
return | current time in ms, uint64_t type |
attention | If board have no RTC battery, when bootup and connect to network, system will automatically sync time by NTP, will cause time() have big change, e.g. before NTP: 10000(ms), after: 1718590639000(ms) If you want to calculate time interval, please use ticks_ms(). |
C++ defination code:
4.3. time_s#
Get current time in s
item | description |
---|---|
return | current time in s, uint64_t type |
attention | If board have no RTC battery, when bootup and connect to network, system will automatically sync time by NTP, will cause time() have big change, e.g. before NTP: 10(s), after: 1718590639(s) |
C++ defination code:
4.4. time_us#
Get current time in us
item | description |
---|---|
return | current time in us, uint64_t type |
attention | If board have no RTC battery, when bootup and connect to network, system will automatically sync time by NTP, will cause time() have big change, e.g. before NTP: 10000000(us), after: 1718590639000000(s) If you want to calculate time interval, please use ticks_us(). |
C++ defination code:
4.5. time_diff#
Calculate time difference in s.
item | description |
---|---|
param | last: last time now: current time, can be -1 if use current time |
return | time difference |
attention | If board have no RTC battery, when bootup and connect to network, system will automatically sync time by NTP, will cause time() have big change, and lead to big value. e.g. before NTP: 1(s), after: 1718590500(s) If you want to calculate time interval, please use ticks_diff(). |
C++ defination code:
4.6. ticks_s#
Get current time in s since bootup
item | description |
---|---|
return | current time in s, double type |
C++ defination code:
4.7. ticks_ms#
Get current time in ms since bootup
item | description |
---|---|
return | current time in ms, uint64_t type |
C++ defination code:
4.8. ticks_us#
Get current time in us since bootup
item | description |
---|---|
return | current time in us, uint64_t type |
C++ defination code:
4.9. ticks_diff#
Calculate time difference in s.
item | description |
---|---|
param | last: last time now: current time, can be -1 if use current time |
return | time difference |
C++ defination code:
4.10. sleep#
Sleep seconds
item | description |
---|---|
param | s: seconds, double type |
C++ defination code:
4.11. sleep_ms#
Sleep milliseconds
item | description |
---|---|
param | ms: milliseconds, uint64_t type |
C++ defination code:
4.12. sleep_us#
Sleep microseconds
item | description |
---|---|
param | us: microseconds, uint64_t type |
C++ defination code:
4.13. fps#
Calculate FPS since last call this method.\nAttention, this method is not multi thread safe, only call this method in one threads.\nIf you want to use in multi threads, please use time.FPS class.\nFPS is average value of recent n(buff_len) times, and you can call fps_set_buff_len(10) to change buffer length, default is 20.\nMultiple invoke this function will calculate fps between two invoke, and you can also call fps_start() fisrt to manually assign fps calulate start point.
item | description |
---|---|
return | float type, current fps since last call this method |
C++ defination code:
4.14. fps_start#
Manually set fps calculation start point, then you can call fps() function to calculate fps between fps_start() and fps().
C++ defination code:
4.15. fps_set_buff_len#
Set fps method buffer length, by default the buffer length is 10.
item | description |
---|---|
param | len: Buffer length to store recent fps value. |
C++ defination code:
4.16. now#
Get current UTC date and time
item | description |
---|---|
return | current date and time, DateTime type |
C++ defination code:
4.17. localtime#
Get local time
item | description |
---|---|
return | local time, DateTime type |
C++ defination code:
4.18. strptime#
DateTime from string
item | description |
---|---|
param | str: date time string format: date time format |
return | DateTime |
C++ defination code:
4.19. gmtime#
timestamp to DateTime(time zone is UTC (value 0))
item | description |
---|---|
param | timestamp: double timestamp |
return | DateTime |
C++ defination code:
4.20. timezone#
Set or get timezone
item | description |
---|---|
param | timezone: string type, can be empty and default to empty, if empty, only return crrent timezone, a "region/city" string, e.g. Asia/Shanghai, Etc/UTC, you can get all by list_timezones function. |
return | string type, return current timezone setting. |
attention | when set new timezone, time setting not take effect in this process for some API, so you need to restart program. |
C++ defination code:
4.21. timezone2#
Set or get timezone
item | description |
---|---|
param | region: string type, which region to set, can be empty means only get current, default empty. city: string type, which city to set, can be empty means only get current, default empty. |
return | list type, return current timezone setting, first is region, second is city. |
attention | when set new timezone, time setting not take effect in this process for some API, so you need to restart program. |
C++ defination code:
4.22. list_timezones#
List all timezone info
item | description |
---|---|
return | A dict with key are regions, and value are region's cities. |
C++ defination code:
4.23. ntp_timetuple#
Retrieves time from an NTP server\nThis function fetches the current time from the specified NTP server and port,\nreturning a tuple containing the time details.
item | description |
---|---|
param | host: The hostname or IP address of the NTP server. port: The port number of the NTP server. Use -1 for the default port 123. retry: The number of retry attempts. Must be at least 1. timeout_ms: The timeout duration in milliseconds. Must be non-negative. |
return | A list of 6 elements: [year, month, day, hour, minute, second] |
C++ defination code:
4.24. ntp_timetuple_with_config#
Retrieves time from an NTP server using a configuration file\nThis function reads the configuration from a YAML file to fetch the current time\nfrom a list of specified NTP servers, returning a tuple containing the time details.
item | description |
---|---|
param | path: The path to the YAML configuration file, which should include: - Config: - retry: Number of retry attempts (must be at least 1) - total_timeout_ms: Total timeout duration in milliseconds (must be non-negative) - NtpServers: - host: Hostname or IP address of the NTP server - port: Port number of the NTP server (use 123 for default) Example YAML configuration: Config: - retry: 3 - total_timeout_ms: 10000 NtpServers: - host: "pool.ntp.org" port: 123 - host: "time.nist.gov" port: 123 - host: "time.windows.com" port: 123 |
return | A list of 6 elements: [year, month, day, hour, minute, second] |
C++ defination code:
4.25. ntp_sync_sys_time#
Retrieves time from an NTP server and synchronizes the system time\nThis function fetches the current time from the specified NTP server and port,\nthen synchronizes the system time with the retrieved time.
item | description |
---|---|
param | host: The hostname or IP address of the NTP server. port: The port number of the NTP server. Use 123 for the default port. retry: The number of retry attempts. Must be at least 1. timeout_ms: The timeout duration in milliseconds. Must be non-negative. |
return | A list of 6 elements: [year, month, day, hour, minute, second] |
C++ defination code:
4.26. ntp_sync_sys_time_with_config#
Retrieves time from an NTP server using a configuration file and synchronizes the system time\nThis function reads the configuration from a YAML file to fetch the current time\nfrom a list of specified NTP servers, then synchronizes the system time with the retrieved time.
item | description |
---|---|
param | path: The path to the YAML configuration file, which should include: - Config: - retry: Number of retry attempts (must be at least 1) - total_timeout_ms: Total timeout duration in milliseconds (must be non-negative) - NtpServers: - host: Hostname or IP address of the NTP server - port: Port number of the NTP server (use 123 for default) Example YAML configuration: Config: - retry: 3 - total_timeout_ms: 10000 NtpServers: - host: "pool.ntp.org" port: 123 - host: "time.nist.gov" port: 123 - host: "time.windows.com" port: 123 |
return | A vector of integers containing the time details: [year, month, day, hour, minute, second] |
C++ defination code:
5. Class#
5.1. FPS#
FPS class to use average filter to calculate FPS.
C++ defination code:
5.1.1. __init__#
FPS class constructor
item | description |
---|---|
type | func |
param | buff_len: Average buffer length, default 20, that is, fps() function will return the average fps in recent buff_len times fps. |
static | False |
C++ defination code:
5.1.2. start#
Manually set fps calculation start point, then you can call fps() function to calculate fps between start() and fps().
item | description |
---|---|
type | func |
static | False |
C++ defination code:
5.1.3. fps#
The same as end function.
item | description |
---|---|
type | func |
return | float type, current fps since last call this method |
static | False |
C++ defination code:
5.1.4. end#
Calculate FPS since last call this method.\nFPS is average value of recent n(buff_len) times, and you can call fps_set_buff_len(10) to change buffer length, default is 20.\nMultiple invoke this function will calculate fps between two invoke, and you can also call fps_start() fisrt to manually assign fps calulate start point.
item | description |
---|---|
type | func |
return | float type, current fps since last call this method |
static | False |
C++ defination code:
5.1.5. set_buff_len#
Set fps method buffer length, by default the buffer length is 10.
item | description |
---|---|
type | func |
param | len: Buffer length to store recent fps value. |
static | False |
C++ defination code:
5.2. DateTime#
Date and time class
C++ defination code:
5.2.1. year#
Year
item | description |
---|---|
type | var |
static | False |
readonly | False |
C++ defination code:
5.2.2. month#
Month, 1~12
item | description |
---|---|
type | var |
static | False |
readonly | False |
C++ defination code:
5.2.3. day#
Day
item | description |
---|---|
type | var |
static | False |
readonly | False |
C++ defination code:
5.2.4. hour#
Hour
item | description |
---|---|
type | var |
static | False |
readonly | False |
C++ defination code:
5.2.5. minute#
Minute
item | description |
---|---|
type | var |
static | False |
readonly | False |
C++ defination code:
5.2.6. second#
Second
item | description |
---|---|
type | var |
static | False |
readonly | False |
C++ defination code:
5.2.7. microsecond#
Microsecond
item | description |
---|---|
type | var |
static | False |
readonly | False |
C++ defination code:
5.2.8. yearday#
Year day
item | description |
---|---|
type | var |
static | False |
readonly | False |
C++ defination code:
5.2.9. weekday#
Weekday, 0 is Monday, 6 is Sunday
item | description |
---|---|
type | var |
static | False |
readonly | False |
C++ defination code:
5.2.10. zone#
Time zone
item | description |
---|---|
type | var |
static | False |
readonly | False |
C++ defination code:
5.2.11. zone_name#
Time zone name
item | description |
---|---|
type | var |
static | False |
readonly | False |
C++ defination code:
5.2.12. __init__#
Constructor
item | description |
---|---|
type | func |
param | year: year month: month day: day hour: hour minute: minute second: second microsecond: microsecond yearday: year day weekday: weekday zone: time zone |
static | False |
C++ defination code:
5.2.13. strftime#
Convert to string
item | description |
---|---|
type | func |
return | date time string |
static | False |
C++ defination code:
5.2.14. timestamp#
Convert to float timestamp
item | description |
---|---|
type | func |
return | float timestamp |
static | False |
C++ defination code: