rtc – 实时时钟¶
该rtc 模块提供对实时时钟的支持。您可以使用 访问和管理 RTCrtc.RTC。 如果存在,它还使用板载 RTC支持time.time() 和time.localtime()功能。
在这些板上可用
- 
rtc.set_time_source(rtc: RTC) → None¶
- 设置 使用的 RTC 时间源 - time.localtime()。默认为- rtc.RTC,但使用它来覆盖时间源以进行测试很有用。例如:- import rtc import time class RTC(object): @property def datetime(self): return time.struct_time((2018, 3, 17, 21, 1, 47, 0, 0, 0)) r = RTC() rtc.set_time_source(r) 
- 
class rtc.RTC¶
- 实时时钟 - 此类代表板载实时时钟。它是一个单例,将始终返回相同的实例。 - 
datetime:time.struct_time¶
- RTC 的当前日期和时间作为 - time.struct_time.- 每当电路板断电时,必须将其设置为当前日期和时间: - import rtc import time r = rtc.RTC() r.datetime = time.struct_time((2019, 5, 29, 15, 14, 15, 0, -1, -1)) - 一旦设置,RTC 将随着时间的推移自动更新该值。您可以读取此属性以获取当前时间的快照: - current_time = r.datetime print(current_time) # struct_time(tm_year=2019, tm_month=5, ...) 
 
-