我试图用mktime
和difftime
来计算两个日期之间的日期差异。其中一个日期是另一个struct
内的struct tm
,另一个日期是main
内部的struct tm
。 mktime
正常工作main
内的日期,但在struct
内保持返回-1的日期。 我想我忽略了如何访问struct
中的struct
,但我无法找到答案。提前致谢。struct tm在另一个struct中 - c
的代码如下
#include <stdio.h>
#include <time.h>
struct consulta_cand {
struct tm nascimento;
};
int main(void)
{
struct consulta_cand candidato;
time_t now;
struct tm final2012;
double timeprint;
now = time(NULL);
final2012 = *localtime(&now);
final2012.tm_mday = 28;
final2012.tm_mon = 10 - 1;
final2012.tm_year = 2012 - 1900;
final2012.tm_hour = 23;
final2012.tm_min = 59;
final2012.tm_sec = 59;
timeprint = mktime(&final2012);
printf("%.f\n", timeprint);
candidato.nascimento = *localtime(&now);
candidato.nascimento.tm_mday = 14;
candidato.nascimento.tm_mon = 10 - 1;
candidato.nascimento.tm_year = 1967 - 1900;
candidato.nascimento.tm_hour = 0;
candidato.nascimento.tm_min = 0;
candidato.nascimento.tm_sec = 0;
timeprint = mktime(&candidato.nascimento);
printf("%.f\n", timeprint);
return 0;
}
你在测试哪个操作系统? – alk
Windows 7,带有TDM-GCC 64位 –