![]() |
![]() |
![]() |
Convert calendar time to local time
#include <time.h> char* ctime( const time_t* timer ); char* ctime_r( const time_t* timer, char* buf );
libc
The ctime() and ctime_r() functions convert the time pointed to by timer to local time and formats it as a string containing exactly 26 characters in the form:
Mon Jul 05 13:08:27 1999\n\0
This function: | Is equivalent to calling: |
---|---|
ctime() | asctime( localtime ( timer ) ); |
ctime_r() | asctime_r( localtime ( timer ), buf ) |
The ctime() function places the result string in a static buffer that's reused each time ctime() or asctime() is called. The result string for ctime_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 NUL character '\0' occupy the last two positions of the string.
Whenever the ctime() or ctime_r() functions are called, the tzset() function is also called.
The calendar time is usually obtained by using the time() function. That time is Coordinated Universal Time (UTC) (formerly known as Greenwich Mean Time (GMT)).
The time set on the computer with the date command reflects Coordinated Universal Time (UTC). The environment variable TZ is used to establish the local time zone. See the section "The TZ environment variable" in the Global Data and the TZ Environment Variable chapter for a discussion of how to set the time zone.
A pointer to the string containing the formatted local time, or NULL if an error occurs.
ctime() is ANSI, POSIX 1003.1; ctime_r() is POSIX 1003.1
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | Yes |
Thread | No |
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |
The asctime() and ctime() functions place their results in a static buffer that's reused for each call to asctime() or ctime().
asctime(), asctime_r(), clock(), difftime(), gmtime(), localtime(), localtime_r(), mktime(), strftime(), time(), tzset()
![]() |
![]() |
![]() |