不确定这是否是时区问题:目前在 SGT 上。
以下代码将 2009 年 4 月 17 日星期五报告为第 6 周 (??),但将 1 月 2 日星期五报告为第 5 周。
#include <time.h>
#include <stdio.h>
#define ONE_DAY 86400
int main() {
time_t StartDate = (time_t) 1239984000;
struct tm StartDateStruct = *localtime(&StartDate);
fprintf(stdout, "Date is %s", asctime(gmtime(&StartDate)));
fprintf(stdout, "Day of the week is = %i\n\n", StartDateStruct.tm_wday);
StartDate = (time_t) 0;
for (int i=0; i<7; i++) {
StartDate = ONE_DAY * i;
StartDateStruct = *localtime(&StartDate);
fprintf(stdout, "Date is %s", asctime(gmtime(&StartDate)));
fprintf(stdout, "Day of the week is = %i\n", StartDateStruct.tm_wday);
}
}
f19 3.11.4-201.fc19.x86_64,gcc 4.8.1 / clang 3.3
提前谢谢你。
迈克尔