ILE C/C++ Run-Time Library Functions


localtime_r() -- Convert Time (Restartable)

Format

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

Language Level: XPG4

Threadsafe: Yes,

Description

This function is the restartable version of localtime(). It is the same as localtime() except that it passes in the place to store the returned structure result.

Return Value

The localtime_r() returns a pointer to the structure result. There is no error return value.

Example that uses localtime_r()

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;
   char buf[50];
 
   ltime=time(&ltime);
   localtime_r(&ltime, &newtime);
   printf("The date and time is %s", asctime_r(&newtime, buf));
}
 
/**************  If the local time is 3:00 p.m. May 31, 1993,  **********
*************************  output should be:  *********************
 
The date and time is Mon May 31 15:00:00 1993
*/

Related Information


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