ctime, ctime_r

Converts a time value to local time in the form of a string.

Library:LibC
Classification:ANSI
Service:Time

Syntax

  #include <time.h> 
   
  char *ctime (
     const time_t  *calendar);
  
  char *ctime_r (
     const time_t  *calendar, 
     char          *timestr);
  

Parameters

calendar

(IN) Points to the time, in seconds since the epoch began, to convert to local time.

timestr

(OUT) Points to a buffer for the converted string.

Return Values

Returns the pointer to the string containing the local time.

The ctime_r function returns a pointer to the timestr buffer. If an error occurs, it returns a NULL pointer.

Remarks

The ctime and ctime_r functions convert the time information in the calendar parameter into a local-time string containing 26 characters.

The string has the form shown in the following example:

     Wed Mar 21 15:58:27 2002\n\0
  

The string is equivalent to:

     asctime (localtime (timer) )
  

All fields have a constant width. The newline character (\n) and the null character (\0) occupy the last two positions of the string. The area containing the returned string is reused each time ctime, ctime_r is called.

The ctime_r function provides the same functionality as ctime, but ctime_r is designed for use with reentrant NLM applications. The ctime_r function allows the caller to pass storage for the results rather than relying on per-thread data.

The ctime function sets the tzname variable; ctime_r does not set this variable For more information, see tzset.

See Also