Syntax
#include <time.h> char *ctime(const time_t *time);Description
The string result produced by ctime contains exactly 26 characters and has the format:
"%.3s %.3s%3d %.2d:%.2d:%.2d %d\n"For example:
Mon Jul 16 02:03:55 1987\n\0
ctime uses a 24-hour clock format. The days are abbreviated to: Sun, Mon, Tue, Wed, Thu, Fri, and Sat. The months are abbreviated to: Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, and Dec. All fields have a constant width. Dates with only one digit are preceded with a blank space. The new-line character (\n) and the null character (\0) occupy the last two positions of the string.
The time and date functions begin at 00:00:00 Universal Time, January 1, 1970. Returns
ctime returns a pointer to the character string result. There is no error return value. A call to ctime is equivalent to:
asctime(localtime(&anytime))
Note: The asctime, ctime, and other time functions may use a common, statically allocated buffer for holding the return string. Each call to one of these functions may destroy the result of the previous call.
Example Code
This example polls the system clock using ctime. It then prints a message giving the current date and time.
#include <time.h> #include <stdio.h> int main(void) { time_t ltime; time(<ime); printf("The time is %s", ctime(<ime)); return 0; /**************************************************************************** The output should be similar to : The time is Thu Dec 15 18:10:23 1994 ****************************************************************************/ }Related Information