2.15 RTC 模块 API 手册
1. 概述
当前 CanMV K230 提供一个类 RTC(实时时钟)模块,用户可以用其设置和获取当前系统时间。
2. API 介绍
RTC 类位于 machine 模块下。
2.1 示例
python
from machine import RTC
# 实例化 RTC
rtc = RTC()
# 获取当前时间
print(rtc.datetime())
# 设置当前时间
rtc.init((2024, 2, 28, 2, 23, 59, 0, 0))1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
2.2 构造函数
python
rtc = RTC()1
参数
无
2.3 init 方法
python
rtc.init(year, month, day, weekday, hours, minutes, seconds, microsec)1
参数
year: 年month: 月day: 日weekday: 星期几,[1-7]hours: 时minutes: 分seconds: 秒microsec: 微秒
返回值
无
2.4 datetime 方法
python
print(rtc.datetime())1
参数
无
返回值
返回当前日期和时间信息,包括:
year: 年mon: 月day: 日wday: 星期几hour: 时min: 分sec: 秒microsec: 微秒