pdf-icon

RTC

案例程序

设置不同时区,并显示实时时钟到屏幕上(年月日时分秒星期)

from m5stack import *
from m5stack_ui import *
from uiflow import *

screen = M5Screen()
screen.clean_screen()
screen.set_screen_bg_color(0xFFFFFF)

label0 = M5Label('label0', x=64, y=64, color=0x000, font=FONT_MONT_14, parent=None)

while True:
  rtc.settime('ntp', host='cn.pool.ntp.org', tzone=8)
  label0.set_text(str(rtc.printRTCtime()))
  wait_ms(2)

功能说明

rtc.settime('ntp', host='cn.pool.ntp.org', tzone=8)
  • 设置不同时区
str(rtc.datetime()[0])
  • 代表年份
str(rtc.datetime()[1])
  • 代表月份
str(rtc.datetime()[2])
  • 代表月份
str(rtc.datetime()[3])
  • 代表星期
str(rtc.datetime()[4)
  • 代表小时
str(rtc.datetime()[5)
  • 代表分钟
str(rtc.datetime()[6)
  • 代表秒钟
rtc.datetime((0, 1, 1, 0, 0, 0, 0, 0))
  • 手动设置时间
str(rtc.datetime())
  • 代表获取实时时钟
str(rtc.printRTCtime())
  • 打印获取的实时时钟
On This Page