Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ mktime(S) — OpenDesktop Software Development System 3.0.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

ctime(S)

difftime(S)

stime(S)

time(S)


 mktime(S)                      6 January 1993                      mktime(S)


 Name

    mktime - converts local time to calendar time

 Syntax


    cc  . . .  -lc


    #include  <time.h>

    time_t mktime (timeptr)
    struct tm *timeptr;                /* Local time structure */


 Description

    The mktime function converts the local time into a calendar value. The
    timeptr argument points to a structure that contains the local time. The
    structure is described in the reference page for asctime. The converted
    time has the same encoding as the values returned by the time function.
    The original values of the tmwday and tmyday 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 tmwday and tmyday appropri-
    ately, and sets the other components to represent the specified calendar
    time, but with their values forced to the normal ranges; the final value
    of tmmday is not set until tmmon and tmyear are determined.

 Notes

    Note that the gmtime, mktime, and localtime functions use a single stati-
    cally allocated buffer for the conversion. Each call to one of these rou-
    tines destroys the result of the previous call.

 Return value

    The mktime function returns the specified calendar time encoded as a
    value of type timet.  If the calendar time cannot be represented, the
    function returns the value -1 (timet).

 See also

    ctime(S), difftime(S), nlcxtime(S), stime(S), time(S)

 Standards conformance

    mktime is conformant with:
    ANSI X3.159-1989 Programming Language -- C.

 Example


       #include <time.h>
       #include <stdio.h>

       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");
       }

    The example above takes a number of days as input and returns the future
    time and date on the specified number of days ahead.


Typewritten Software • bear@typewritten.org • Edmonds, WA 98026