2

GCC provides the macros __DATE__ and __TIME__ that give string constants with the build date and time. However they seem to be giving the time in UTC. Is there some macro to get the build time in local time zone?

Ajoy
  • 525
  • 1
  • 9
  • 20
  • Use backtics for text that shouldn't be processed by the SO's markup engine: `\`__DATE__\``. Now to the question itself: I can't reproduce your problem: `$ echo __TIME__ | gcc -E -xc - | tail -1` gives me `"13:02:29"` which is correct and not UTC: `$ date +"%T %Z %z"` -> `13:02:31 MSK +0300` – Vladislav Ivanishin Jul 11 '19 at 10:07
  • Seems to be happening with two of my machines. – Ajoy Jul 11 '19 at 11:33
  • Is the output different from output of the `date` command? Does it happen with other compilers/preprocessors also? Perhaps you have some unusual environment variables set (you can list them with `env`)? Most importantly, what is the output of `readlink /etc/localtime`? – Vladislav Ivanishin Jul 11 '19 at 11:45
  • Output of readlink is empty string. Nothing unusual in env. But output different from date command. GCC version is old though 4.7.2. – Ajoy Jul 11 '19 at 11:50
  • _Output of readlink is empty string_ — well, then I suppose, you either have time zone misconfigured, or just configuration on your system is different (and then it must be unusual, or just unexpected to gcc...). On my machine, `/ect/localtime` is a symlink to `/usr/share/zoneinfo/Europe/Moscow`. What system are you on? Also, out of interest I'd try a different compiler, e.g. clang, if it's easy to install. – Vladislav Ivanishin Jul 11 '19 at 12:01

1 Answers1

0

Some gcc compilers have such behavior - macros __TIME__ outputs an UTC time, not local. I've seen such effect with arm-linux-gnueabihf-gcc from Xilinx petalinux generated sdk. You can verify your compiler using command line suggested by Vladislav Ivanishin (see comments).

UPD: By request from comment below I've added link to the Vladislav Ivanishin's comment: GCC get build date and time in local timezone

And the command line to verify gcc is: echo __TIME__ | gcc -E -xc - | tail -1

Andrey My
  • 1
  • 3
  • Please copy Mr. Ivanishin's command line into the answer with proper credits. It's unclear which one you refer to. – Joooeey May 31 '22 at 20:26