의 이해할 수없는 행동 :strptime c-function이 구조를 변경하는 이유는 무엇입니까? 기능 <code>strptime()</code>의
이#define _XOPEN_SOURCE
#include <stdio.h>
#include <time.h>
double getPeriod(char * dateStart, char * dateStop) {
struct tm tmStart, tmStop;
time_t timeStampStart, timeStampStop;
strptime(dateStart, "%Y-%m-%d %H:%M:%S", &tmStart);
strptime(dateStop, "%Y-%m-%d %H:%M:%S", &tmStop);
timeStampStart = mktime(&tmStart);
timeStampStop = mktime(&tmStop);
printf("%d\t%d\n", tmStart.tm_hour, tmStop.tm_hour);
}
int main()
{
getPeriod("2016-12-05 18:14:35", "2016-12-05 18:18:34");
return 0;
}
출력은 :
17 18
왜 이런 일이 무엇입니까? mktime
에 전달 될 때
컴파일러 GCC (GCC) 6.2.1 OS 리눅스
'timeStampStart'의'tm_isdst' 멤버와'timeStampStop' 멤버를 -1로 초기화해야합니다. – user4815162342
[GCC와 Clang에서 작동하는 것 같습니다] (http://coliru.stacked-crooked.com/a/6b54f234cc33eb6c) – AndyG
@ user4815162342 : 오, 저 일광 절약 시간제는 항상 그런 고통입니다! 그리고 나는 당신이'tmStart'와'tmStop'을 의미한다고 생각합니다. – AndyG