1
#include<stdio.h>
#include<time.h>

int main(void){
    time_t now = time(NULL);
    printf("%s\n", ctime(&now));
    return 0;
}

This is compiled using GCC and run. Result: Wed May 10 19:13:18 2023 Actual: Sat May 13 09:45:37 2023 (PC system time as correctly displayed) Why the difference? The code could not be simpler!

Environment: I'm running Windows Subsystem for Linux WSL2 on a Windows 11 PC. I don't know if that is significant

Tried researching for similar problems - but this is not a UTC/local time issue.

Mat
  • 202,337
  • 40
  • 393
  • 406
Dabbo
  • 143
  • 5

1 Answers1

1

can you run the following command and print the output ?

sudo hwclock -s
  • Thu May 11 11:42:49 2023. That's strange in that it has moved a day in the right direction but not there yet. (PS I tried this before trying Rahul460 suggestion whcih is what I'll try next) – Dabbo May 13 '23 at 09:13
  • All good now after restarting WSL. Thanks! – Dabbo May 13 '23 at 09:29