struct tm reverttime, leasetime;
int Usetimesecond;
GetLocalTime(&sysTime);
reverttime.tm_year = sysTime.wYear;
reverttime.tm_mon = sysTime.wMonth;
reverttime.tm_mday = sysTime.wDay;
reverttime.tm_hour = sysTime.wHour;
reverttime.tm_min = sysTime.wMinute;
reverttime.tm_sec = sysTime.wSecond;
Usetimesecond = mktime(&reverttime);
为什么Usetimesecond的值总是-1呢?
3 个解决方案
#1
mktime 这个函数怎么处理的呢
#2
mktime
Header File
time.h
Category
Time and Date Routines
Prototype
time_t mktime(struct tm *t);
Description
Converts time to calendar format.
Converts the time in the structure pointed to by t into a calendar time with the same format used by the time function. The original values of the fields tm_sec, tm_min, tm_hour, tm_mday, and tm_mon are not restricted to the ranges described in the tm structure. If the fields are not in their proper ranges, they are adjusted. Values for fields tm_wday and tm_yday are computed after the other fields have been adjusted.
The allowable range of calendar times is Jan 1 1970 00:00:00 to Jan 19 2038 03:14:07.
Return Value
On success, mktime returns calendar time as described above.
On error (if the calendar time cannot be represented), mktime returns -1.
Header File
time.h
Category
Time and Date Routines
Prototype
time_t mktime(struct tm *t);
Description
Converts time to calendar format.
Converts the time in the structure pointed to by t into a calendar time with the same format used by the time function. The original values of the fields tm_sec, tm_min, tm_hour, tm_mday, and tm_mon are not restricted to the ranges described in the tm structure. If the fields are not in their proper ranges, they are adjusted. Values for fields tm_wday and tm_yday are computed after the other fields have been adjusted.
The allowable range of calendar times is Jan 1 1970 00:00:00 to Jan 19 2038 03:14:07.
Return Value
On success, mktime returns calendar time as described above.
On error (if the calendar time cannot be represented), mktime returns -1.
#3
问题是你这个sysTime哪定义的,赋值了没有
#1
mktime 这个函数怎么处理的呢
#2
mktime
Header File
time.h
Category
Time and Date Routines
Prototype
time_t mktime(struct tm *t);
Description
Converts time to calendar format.
Converts the time in the structure pointed to by t into a calendar time with the same format used by the time function. The original values of the fields tm_sec, tm_min, tm_hour, tm_mday, and tm_mon are not restricted to the ranges described in the tm structure. If the fields are not in their proper ranges, they are adjusted. Values for fields tm_wday and tm_yday are computed after the other fields have been adjusted.
The allowable range of calendar times is Jan 1 1970 00:00:00 to Jan 19 2038 03:14:07.
Return Value
On success, mktime returns calendar time as described above.
On error (if the calendar time cannot be represented), mktime returns -1.
Header File
time.h
Category
Time and Date Routines
Prototype
time_t mktime(struct tm *t);
Description
Converts time to calendar format.
Converts the time in the structure pointed to by t into a calendar time with the same format used by the time function. The original values of the fields tm_sec, tm_min, tm_hour, tm_mday, and tm_mon are not restricted to the ranges described in the tm structure. If the fields are not in their proper ranges, they are adjusted. Values for fields tm_wday and tm_yday are computed after the other fields have been adjusted.
The allowable range of calendar times is Jan 1 1970 00:00:00 to Jan 19 2038 03:14:07.
Return Value
On success, mktime returns calendar time as described above.
On error (if the calendar time cannot be represented), mktime returns -1.
#3
问题是你这个sysTime哪定义的,赋值了没有