用difftime()和mktime()配合使用
mktime()函数原型time_t __cdecl mktime(struct tm *)
tm是个struct,定义是
struct tm {
int tm_sec; /* seconds after the minute - [0,59] */
int tm_min; /* minutes after the hour - [0,59] */
int tm_hour; /* hours since midnight - [0,23] */
int tm_mday; /* day of the month - [1,31] */
int tm_mon; /* months since January - [0,11] */
int tm_year; /* years since 1900 */
int tm_wday; /* days since Sunday - [0,6] */
int tm_yday; /* days since January 1 - [0,365] */
int tm_isdst; /* daylight savings time flag */
};
用mktime分别得到你要计算的时间和1970年1月1日0点0分0秒的两个time_t
然后在用difftime()即可算出结果
difftime()定义
double __cdecl difftime(time_t,time_t);