#| ESP32 教學 | MicroPython | RTC 實時時鐘 Real Time Clock
#https://jimirobot.tw/esp32-micropython-rtc-real-time-clock-tutorial-211/
import machine
import time
# 定義中文星期的列表
chinese_weekdays = ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"]
rtc = machine.RTC()
rtc.init((2024, 1, 2, 3, 4, 5, 6, 7))
while True:
t = rtc.datetime()
# 取得中文星期
chinese_weekday = chinese_weekdays[t[3]]
# 修正這一行,加上格式化字串的 {} 符號,顯示中文星期
print("{:02}-{:02}-{:02} {} {:02}:{:02}:{:02}".format(t[0], t[1], t[2], chinese_weekday, t[4], t[5], t[6]))
time.sleep(1)