|
|
#include <time.h>time_t mktime (timeptr) struct tm *timeptr; /* Local time structure */
tm_wday
and
tm_yday
components of the timeptr structure are
ignored, and the original values of the other components are not
restricted to their normal ranges.
If successful, mktime sets the values of tm_wday
and
tm_yday
appropriately, and sets the other components to
represent the specified calendar time, but with their values
forced to the normal ranges; the final value of tm_mday
is
not set until tm_mon
and tm_year
are determined.
ANSI X3.159-1989 Programming Language -- C .
#include <time.h> #include <stdio.h>The example above takes a number of days as input and returns the future time and date on the specified number of days ahead.struct tm when; time_t now; time_t result; int days;
main() { printf("How many days to look ahead? "); scanf("%d", &days);time(&now); when = *localtime(&now); when.tm_mday = when.tm_mday + days; if ((result = mktime(&when)) != (time_t)-1) printf("\n%d days from now the time will be %s", days, asctime(&when)); else perror("mktime failed"); }