[Previous] [Contents] [Next]

asctime(), asctime_r()

Convert time information to a string

Synopsis:

#include <time.h>

char* asctime( const struct tm* timeptr );

char* asctime_r( const struct tm* timeptr, 
                 char* buf );

Library:

libc

Description:

The asctime() and asctime_r() functions convert the time information in the structure pointed to by timeptr into a string containing exactly 26 characters with the form:

Thu Jul 01 15:58:27 1999\n\0

The asctime() function places the result string in a static buffer that's reused every time asctime() or ctime() is called. The result string for asctime_r() is contained in the buffer pointed to by buf. The buffer must be large enough to hold at least 26 characters.

All fields have a constant width. The newline character ('\n') and a NUL character ('\0') occupy the last two positions of the string.

Returns:

A pointer to the character string result, or NULL if an error occurs.

Classification:

asctime() is ANSI; asctime_r() is POSIX 1003.1 (Threads)

asctime()

Safety:
Cancellation point No
Interrupt handler No
Signal handler No
Thread No

asctime_r()

Safety:
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes

Caveats:

The asctime() and ctime() functions place their results in a static buffer that's reused for each call to asctime() or ctime().

See also:

clock(), ctime(), difftime(), gmtime(), localtime(), localtime_r(), mktime(), strftime(), time(), tm, tzset()


[Previous] [Contents] [Next]