Converts local time to a calendar value.
Include
<time.h>
Prototype
time_t mktime(struct tm *tptr);
Argument
tptr
Return Value
Returns the calendar time encoded as a value of time_t
.
Remarks
If the calendar time cannot be represented, the function returns -1 cast as a
time_t
(i.e. (time_t) -1)
.
Example
#include <time.h>
#include <stdio.h>
int main(void)
{
time_t timer, whattime;
struct tm *newtime;
timer = 1066668182; /* Mon Oct 20 16:43:02 2003 */
/* localtime allocates space for struct tm */
newtime = localtime(&timer);
printf("Local time = %s", asctime(newtime));
whattime = mktime(newtime);
printf("Calendar time as time_t = %ld\n",
whattime);
}
Example Output
Local time = Mon Oct 20 16:43:02 2003
Calendar time as time_t = 1066668182