strptime()
日付/時刻文字列をそのコンポーネント値に解析するために使用しようとしています。テストとして、次のコードを使用して、固定の日時文字列を解析し、結果の値を出力しようとしました。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
int main(void)
{
struct tm tm;
memset(&tm, 0, sizeof(struct tm));
strptime("2001/11/12 18:31:01", "%Y/%m/%d %H:%M:%S", &tm);
printf("year: %d; month: %d; day: %d;\n",
tm.tm_year, tm.tm_mon, tm.tm_mday);
printf("hour: %d; minute: %d; second: %d\n",
tm.tm_hour, tm.tm_min, tm.tm_sec);
exit(EXIT_SUCCESS);
}
私が得る出力は次のとおりです。
year: 101; month: 10; day: 12;
hour: 18; minute: 31; second: 1
他の値は問題ないように見えますが、年と月が入力と一致しません ( 2001/11/12 18:31:01
)。何故ですか?