Skip to content

Commit 078d813

Browse files
committed
add adjustment for time zone offset
1 parent b4451c3 commit 078d813

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

micropython/examples/inky_frame/inky_frame_rtc_demo.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0"
88
from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.3"
99

10+
# Set tz_offset to be the number of hours off of UTC for your local zone.
11+
# Examples: tz_offset = -7 # Pacific time (PST)
12+
# tz_offset = 1 # CEST (Paris)
13+
tz_offset = 0
14+
tz_seconds = tz_offset * 3600
15+
1016
# Sync the Inky (always on) RTC to the Pico W so that "time.localtime()" works.
1117
inky_frame.pcf_to_pico_rtc()
1218

@@ -36,7 +42,7 @@
3642
def status_handler(mode, status, ip):
3743
print(mode, status, ip)
3844

39-
year, month, day, hour, minute, second, dow, _ = time.localtime()
45+
year, month, day, hour, minute, second, dow, _ = time.localtime(time.time() + tz_seconds)
4046

4147
# Connect to the network and get the time if it's not set
4248
if year < 2023:
@@ -60,7 +66,7 @@ def status_handler(mode, status, ip):
6066
graphics.text("Failed to connect!", 0, 40)
6167

6268
# Display the date and time
63-
year, month, day, hour, minute, second, dow, _ = time.localtime()
69+
year, month, day, hour, minute, second, dow, _ = time.localtime(time.time() + tz_seconds)
6470

6571
date_time = f"{year:04}/{month:02}/{day:02} {hour:02}:{minute:02}:{second:02}"
6672

0 commit comments

Comments
 (0)