【发布时间】:2023-03-10 23:02:01
【问题描述】:
希望有人可以提供帮助。我正在修复某人很久以前编写的 C 代码中的一个问题,而他后来继续前进。
这段代码输出特定文件的时间戳。该代码在 Windows 上运行时运行良好,但在 Linux 上运行时显示年份不正确。 linux 上没有显示年份,它显示的是 35222。有人知道这里有什么问题吗?
谢谢
Windows 输出:
Source file: test.dtl, Created: Mon, 27 May, 2013 at 16:13:20
Linux 输出:
Source file: test.dtl, Created: Mon, 27 May, 35222 at 16:13:20
C代码中的函数:
void SummaryReport ( report_t *report, char *dtlName)
{
LogEntry(L"SummaryReport entry\n");
int i;
wchar_t *rootStrType,*localStr,timeStr[48];
wchar_t fileBuff[64];
struct tm *timeVals;
timeVals = localtime (&logHdr.date);
wcsftime (timeStr,47,L"%a, %#d %b, %Y at %X",timeVals);
/* Print the header information */
DisplayReportFile (report);
ReportEntry (report,L" Filesystem Audit Summary Report\n\n");
ReportEntry (report,L"Source file: %s, Created: %ls\n\n",dtlName,timeStr);
ReportEntry (report,L"Server: %ls",srvrName);
…
}
【问题讨论】:
-
Linux 系统上的日期——特别是年份——设置是否正确?
-
Linux 比 Windows 先进得多。
-
我猜,这是由于 Windows 和 Unix 使用不同的时基。 Unix 从 1.1.1970 开始计算秒数 - 我不知道 Windows 做了什么,但我敢打赌不同的东西......
-
logHdr.date来自哪里? -
尝试打印出
timeVals->tm_year以确保您的 tm 值正确。