Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought



     MKTIME(S)                 UNIX System V                 MKTIME(S)



     Name
          mktime - converts local time to calendar time

     Syntax
          #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 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.

     Notes
          Note that the gmtime, mktime, and localtime functions use a
          single statically allocated buffer for the conversion. Each
          call to one of these routines destroys the result of the
          previous call.

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

     See Also
          asctime(S), gmtime(S), localtime(S), time(S)

     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.

     Standards Conformance
          mktime is conformant with:
          ANSI X3.159-198X C Language Draft Standard, May 13, 1988.


                                             (printed 6/20/89)



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