0

I use strftime to format the time. %Z format the time timezone. But the result is GMT compiled with arm-linux-gnueabihf-gcc, UTC compiled with mipsel-openwrt-linux-uclibc-gcc.

I don't know why.

time_t t = time(NULL);
char stat_timestamp[24] = {0};
strftime(stat_timestamp, sizeof stat_timestamp, "%F %T %Z", gmtime(&t));
printf("gmtime: %s\n", stat_timestamp);

compiled with arm-linux-gnueabihf-gcc:

gmtime: 2018-12-21 XX:XX:XX GMT

compiled with mipsel-openwrt-linux-uclibc-gcc:

gmtime: 2018-12-21 XX:XX:XX UTC
Student
  • 805
  • 1
  • 8
  • 11
  • The two systems use a different name for the timezone. Is there something more that that you seek? I recommend using a wider `char stat_timestamp[24]` --> `char stat_timestamp[100]` for this investigation as insufficient buffers result in an indeterminate `stat_timestamp[]`. – chux - Reinstate Monica Dec 21 '18 at 04:38
  • 1
    Timezone names come from system configuration, not the C library. – Barmar Dec 21 '18 at 04:40

2 Answers2

1

Why the result of 'gmtime, strftime' is different

  • Implementation defined behavior.

C does not require it to be the same across various platforms.

%Z is replaced by the locale’s time zone name or abbreviation, or by no characters if no time zone is determinable. [tm_isdst] C11dr §7.26.3.5 3

In the "C" locale ... %Z implementation-defined. §7.26.3.5 7

Note that UTC is akin to GMT. See also Is GMT same as UTC?

chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256
0

The correct value is actually GMT, which is a time zone. UTC is not a time zone (unless possibly if you're using it as shorthand for UTC+0) but is instead a time standard, but people often mistakenly use UTC as a zone.

There is no real restriction on what implementations return as the time zone since the standard has only this to say:

%Z is replaced by the locale's time zone name or abbreviation, or by no characters if no time zone is determinable.

The local time zone and daylight savings time are some of the items lised under "Unspecified behaviour".

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953