두 datetime (년, 월, 일,시, 분, 초)의 차이를 계산할 수있는 함수가 필요합니다. 차이를 동일한 형식으로 반환하십시오. 이 작은 유닛 인 것에C에서 datetime 차이 계산
는 (제 케이스의) datetime
값을 나타내는 일체형 (바람직 long long
또는 unsigned long long
)로 datetime
변환 :
int main(){
struct datetime dt_from;
init_datetime(&dt_from, 1995, 9, 15, 10, 40, 15);
struct datetime dt_to;
init_datetime(&dt_to, 2004, 6, 15, 10, 40, 20);
struct datetime dt_res;
datetime_diff(&dt_from, &dt_to, &dt_res);
return 0;
}
void datetime_diff(struct datetime *dt_from, struct datetime *dt_to
, struct datetime *dt_res) {
//What can I do here to calculate the difference, and get it in the dt_res?
}
하는 당신은 표준 ['difftime' (같은 것을 의미 HTTP : //en.cppreference.com/w/c/chrono/difftime) function? –
struct datetime은 이식 가능하지 않습니다. "time.h"라이브러리를 사용해야하므로 struct tm – jurhas
을 사용해야합니다. 1)'struct datetime'의 정의를 게시하십시오. 2)'init_datetime()()'의 포스트 정의 3) 코드가 어떻게 오버 플로우를 처리해야 하는지를 설명하는 것이 유용 할 것이다. (최대 시간 - 최소 시간) – chux