localtime -- Convert Time

Format

#include <time.h>
struct tm *localtime(const time_t *timeval);

Language Level: ANSI, POSIX, XPG4
localtime breaks down timeval, corrects for the local time zone and Daylight Saving Time, if appropriate, and stores the corrected time in a structure of type tm.

The time value is usually obtained by a call to the time function.

Notes:

  1. gmtime and localtime may use a common, statically allocated buffer for the conversion. Each call to one of these functions may alter the result of the previous call.
  2. Calendar time is the number of seconds that have elapsed since EPOCH, which is 00:00:00, January 1, 1970 Universal Coordinate Time (UTC).
  3. This function is locale sensitive.

On both OS/2 and Windows, the time and date functions begin at 00:00:00 Universal Coordinate Time, January 1, 1970, and do not have an upper limit.

Return Value
localtime returns a pointer to the structure result.

If unsuccessful, it returns NULL.

Example
This example queries the system clock and displays the local time.

#include <time.h>
#include <stdio.h>
int main(void)
{
   struct tm *newtime;
   time_t ltime;
   time(&ltime);
   newtime = localtime(&ltime);
   printf("The date and time is %s", asctime(newtime));
   return 0;
   /****************************************************
      The output should be similar to:
      The date and time is Wed Oct 31 15:00:00 1995
   ****************************************************/
}


asctime -- Convert Time to Character String
ctime -- Convert Time to Character String
gmtime -- Convert Time
mktime -- Convert Local Time
setlocale -- Set Locale
time -- Determine Current Time
<locale.h>
<time.h>