Skip to content

Commit fd98656

Browse files
author
Martin Crossley
committed
Clarify use of ctime()
1 parent 6cc4cd3 commit fd98656

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

pico_w/wifi/ntp_system_time/ntp_system_time.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,16 @@ int main() {
105105
get_time_utc(&ts);
106106

107107
// if you just want a string representation of the current time and you're not interested
108-
// in the individual date/time fields, you could simply call ctime(&(ts.tv_sec)) here
109-
// (if you have set 'TZ' then the result will be in local time, otherwise UTC)
110-
111-
// unpack the individual date/time fields (if you have set 'TZ' then the values will be
112-
// in local time, otherwise UTC)
108+
// in the individual date/time fields, then here you can simply call:
109+
// printf("%s", ctime(&(ts.tv_sec)));
110+
// The string produced is the same as `asctime()` as used below. Note that if you set
111+
// 'TZ' then the output will be in local time, otherwise UTC.
112+
113+
// you can unpack the raw UTC seconds count into individual date/time fields like this.
114+
// Again, if you set 'TZ' then the values will be in local time, otherwise UTC. Note
115+
// that by default `pico_localtime_r()` just calls `localtime_r()` from the standard 'C'
116+
// library, but the declaration is 'weak' so that a user can override it with their own
117+
// implementation if desired.
113118
pico_localtime_r(&(ts.tv_sec), &tm);
114119

115120
// display individual date/time fields in human readable form

0 commit comments

Comments
 (0)