C程序函数ctime()返回的时间/日期不正确 – 日期偏差3天。

huangapple go评论66阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年5月13日 16:55:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76241880.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定