英文:
C program function ctime() returns wrong time/date - out by 3 days
问题
The code you provided is a C program that prints the current time. The difference in the displayed time could be due to your system's time settings, including the time zone configuration. The fact that you're running it in a Windows Subsystem for Linux (WSL2) environment on a Windows 11 PC might also play a role.
代码中提供的是一个C程序,用于打印当前时间。显示时间差异可能是由于您系统的时间设置,包括时区配置引起的。您在Windows 11 PC上的Windows子系统中运行它可能也会起到一定作用。
英文:
#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.
答案1
得分: 1
Sure, here is the translation of the command you provided:
请运行以下命令并打印输出:
sudo hwclock -s
英文:
can you run the following command and print the output ?
sudo hwclock -s
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论