Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <b>mktime() convert time to calendar value</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 mktime()                Convert Time to Calendar Value

 #include   <time.h>

  time_t mktime(time_ptr);
  struct tm *time_ptr;   Local time structure

    mktime() converts the time contained in time_ptr, expressed as local
    time, into a calendar value. The following structure holds the values
    to be converted:

           struct tm {
               int tm_sec;         Seconds after the minute (0 - 59)
               int tm_min;         Minutes after the hour (0 - 59)
               int tm_hour;   Hours since midnight (0 - 23)
               int tm_mday;   Day of the month (1 - 31)
               int tm_mon;         Months since January (0 - 11)
               int tm_year;   Years since 1900
               int tm_wday;   Days since Sunday (0 - 6)
               int tm_yday;   Days since January 1 (0 - 365)
               int tm_isdst;  Daylight savings time flag
               };

    The original values of of tm_wday and tm_yday are ignored, and the
    original values of the other components are not restricted to their
    original 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. The final value of tm_mday is not set until
    tm_mon and tm_year are determined.

    Returns:    mktime() returns the specified calendar time encoded as a
                valueof type time_t. If the calendar time cannot be
                represented, the function returns the value -1 cast as
                type time_t.

      Notes:    The time_t value has a format intended for use with other
                ANSI functions such as localtime(), difftime(), and
                gmtime() to permit portable time calculations. Its format
                may change across C implementations.

                MS-DOS does not understand dates prior to 1980. If
                time_ptr references a prior date mktime() returns -1.

   Portability:     ANSI

 -------------------------------- Example ---------------------------------

 This program tells the day of the week of January 1, 1989

           #include <time.h>

           char *wday[] = { "Sunday", "Monday", "Tuesday", "Wednesday",
                            "Thursday", "Friday", "Saturday" };

           struct tm time_ptr;

           main()
           {
              time_ptr.tm_year = 1989 - 1900;
              time_ptr.tm_mon  = 1 - 1;
              time_ptr.tm_mday = 1;
              time_ptr.tm_hour = 0;
              time_ptr.tm_min  = 0;
              time_ptr.tm_sec  = 0;
              time_ptr.tm_isdst  = -1;

              if (mktime(&time_ptr) != (time_t) -1)
                 printf("January 1, 1989 is a %s\n", wday[time_ptr.tm_wday]);
              else
                 printf("Unable to calculate day of week\n");
           }


See Also: asctime() gmtime() localtime() time() difftime()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson