求以2000年1月1日0点0分为起始时间,到当前时间,换算成的秒数:
SYSTEMTIME sysTime;
struct tm basetime, nowtime;
time_t tTime, tTimeBase; //time_t为64位整形__int64或长整形long
GetSystemTime(&systime); //获取系统时间,以UTC表示
nowtime.tm_year = systime.wYear-1900;
nowtime.tm_mon = systime.wMonth-1;
nowtime.tm_mday = systime.wDay;
nowtime.tm_hour = sysTime.wHour;
nowtime.tm_min = sysTime.wMinute;
nowtime.tm_sec = sysTime.wSecond;
nowtime.tm_isdst = 0;
basetime.tm_year = 2000-1900;
basetime.tm_mon = 0;
basetime.tm_mday = 1;
basetime.tm_hour = 0;
basetime.tm_min = 0;
basetime.tm_sec = 0;
basetime.tm_isdst = 0;
tTimeBase = mktime(&basetime); //将struct tm结构的时间转换为从1970.1.1 00:00:00至2000.1.1 00:00:00的秒数
tTime = mktime(&nowtime); //将struct tm结构的时间转换为从1970.1.1 00:00:00至今的秒数
//以2000年1月1日0点0分为起始日期,到当前时间,换算成秒数(4字节十六进制),高位在前
DWORD dwTime = difftime(tTime, tTimeBase); //返回两个时间相差的秒数
头文件:WinBase.h,SYSTEMTIME定义:
typedef struct _SYSTEMTIME {
WORD wYear; //The current year
WORD wMonth; //The current month; January is 1
WORD wDayOfWeek; //The current day of the week; Sunday is 0, Monday is 1, and so on
WORD wDay; //The current day of the month
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME;
头文件:time.h,struct tm定义
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 */
};
找的资料,方便查看:
http://blog.sina.com.cn/s/blog_5669080b0100p2ox.html
http://blog.csdn.net/love_gaohz/article/details/6637625
http://blog.csdn.net/zzzzyu/article/details/44937835
http://www.cnblogs.com/renjiashuo/p/6913668.html