Skip to content

Commit ec5617b

Browse files
author
Martin Crossley
committed
remove hardcoding of TZ names
1 parent 8af2a1f commit ec5617b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

pico_w/wifi/ntp_system_time/ntp_system_time.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ int main() {
9494
// OPTIONAL: set the 'TZ' env variable to the local POSIX timezone (in this case Europe/London,
9595
// to create your own see https://ftp.gnu.org/old-gnu/Manuals/glibc-2.2.3/html_node/libc_431.html)
9696
setenv("TZ", "BST0GMT,M3.5.0/1,M10.5.0/2", 1);
97+
9798
// If the environment contains a valid 'TZ' definition then functions like ctime(), localtime()
9899
// and their variants automatically give results converted to the local timezone instead of UTC
99100
// (see below).
@@ -119,9 +120,10 @@ int main() {
119120
pico_localtime_r(&(ts.tv_sec), &tm);
120121

121122
// display individual date/time fields in human readable form
122-
printf("%s: %s", tm.tm_isdst ? "BST": "GMT", asctime(&tm));
123+
printf("%s: %s", tm.tm_isdst ? tzname[0]: tzname[1], asctime(&tm));
123124
// asctime(), ctime() and their variants produce strings of the form "Mon Oct 27 22:06:08 2025\n"
124125
// - note the trailing '\n'.
126+
// extern char *tzname[2] (from time.h) holds the names of the POSIX TZ timezones if defined
125127

126128
} else {
127129
puts("system time not yet initialised");

0 commit comments

Comments
 (0)