C time ctime() Function
Example
Print the current date and time:
time_t now = time(NULL);
printf("%s", ctime(&now));
Definition and Usage
The ctime() function converts a time_t value into a string with the local date and time, like Thu Jun 26 14:30:05 2025.
The string always has this format, and it ends with a new line (\n), so you do not need \n in printf().
ctime(&now) gives the same result as asctime(localtime(&now)).
Tip: To choose your own format, use strftime().
The ctime() function is defined in the <time.h> header file.
Syntax
char *ctime(const time_t *timer);
Parameter Values
| Parameter | Description |
|---|---|
| timer | Required. A pointer to a time_t value, for example from time(). |
Technical Details
| Returns: | A pointer to a string with the date and time. The string is shared, so the next call to ctime() or asctime() overwrites it. |
|---|
Related Pages
Read more about dates and times in our C Date and Time Tutorial.