不确定这是否是时区问题:目前正在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
提前感谢你。
迈克尔