mktime64() — Convert Local Time

Format

#include <time.h>
time64_t mktime64(struct tm *time);

Language Level: ILE C Extension

Threadsafe: Yes.

Locale Sensitive: The behavior of this function might be affected by the LC_TOD category of the current locale.

Description

The mktime64() function converts a stored tm structure (assumed to be in job local time) pointed to by time, into a time64_t value suitable for use with other time functions. After the conversion, the time64_t value will be considered Universal Coordinate Time (UTC). For this conversion, mktime64() checks the current locale settings for the local time zone and daylight saving time (DST). If these values are not set in the current locale, mktime64() gets the local time zone and DST settings from the current job. If the DST is set in the locale but the time zone information is not, the DST information in the locale is ignored. The mktime64() function then uses the time zone information of the current job to determine UTC.

The values of some structure elements pointed to by time are not restricted to the ranges shown for gmtime64().

The values of tm_wday and tm_yday passed to mktime64() are ignored and are assigned their correct values on return.

A positive or 0 value for tm_isdst causes mktime() to presume initially that DST, respectively, is or is not in effect for the specified time. A negative value for tm_isdst causes mktime() to attempt to determine whether DST is in effect for the specified time.

Note:
The supported date and time range for this function is 01/01/1970 00:00:00 through 12/31/9999 23:59:59.

Return Value

The mktime64() function returns Universal Coordinate Time (UTC) having type time64_t. The value (time_t)(-1) is returned if the Universal Coordinate Time cannot be represented or if the given time is out of range. If the given time is out of range, errno is set to EOVERFLOW.

Example that uses mktime64()

This example prints the day of the week that is 40 days and 16 hours from the current date.

#include <stdio.h>
#include <time.h>
 
char *wday[] = { "Sunday", "Monday", "Tuesday", "Wednesday",
                 "Thursday", "Friday", "Saturday" };
 
int main(void)
{
  time64_t t1, t3;
  struct tm *t2;
 
  t1 = time64(NULL);
  t2 = localtime64(&t1);
  t2 -> tm_mday += 40;
  t2 -> tm_hour += 16;
  t3 = mktime64(t2);
 
  printf("40 days and 16 hours from now, it will be a %s \n",
          wday[t2 -> tm_wday]);
}
 
/*******************  Output should be similar to:  ***************
 
40 days and 16 hours from now, it will be a Sunday
*/

Related Information



[ Top of Page | Previous Page | Next Page | Contents | Index ]