C time asctime() Function
Example
Print the date and time from a struct tm:
time_t now = time(NULL);
struct tm *t = localtime(&now);
printf("%s", asctime(t));
Definition and Usage
The asctime() function converts a struct tm into a string with the 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).
Tip: To choose your own format, use strftime().
The asctime() function is defined in the <time.h> header file.
Syntax
char *asctime(const struct tm *timeptr);
Parameter Values
| Parameter | Description |
|---|---|
| timeptr | Required. A pointer to a struct tm with the date and time, for example from localtime(). |
Technical Details
| Returns: | A pointer to a string with the date and time. The string is shared, so the next call to asctime() or ctime() overwrites it. |
|---|
Related Pages
Read more about dates and times in our C Date and Time Tutorial.