CKTIS / C
asctime — fixed-format date and time text
asctime converts struct tm into fixed-format text. In C23, the function is deprecated and should be avoided in new code.
Version: C23; repository compiler flag, production runtime not attested
Syntax
#include <time.h>
[[deprecated]] char *asctime(const struct tm *timeptr);asctime from <time.h> reads a struct tm and returns a pointer to text: 25 characters plus \0, with English abbreviations and a trailing \n. It does not convert time zones or calculate the weekday. tm_mon counts months from zero; tm_year counts years since 1900.
NULL, fields outside their normal ranges, or a year outside 1000–9999 cause undefined behavior. The library owns the buffer: do not free it; subsequent asctime or ctime calls may overwrite it. The function is not reentrant and does not guarantee freedom from data races. C23 marks it [[deprecated]]; prefer strftime with your own buffer for new code.
Examples
#include <stdio.h>
#include <time.h>
int main(void)
{
const struct tm value = {
.tm_year = 123,
.tm_mon = 0,
.tm_mday = 1,
.tm_wday = 0,
.tm_yday = 0,
.tm_hour = 12,
.tm_min = 34,
.tm_sec = 56,
.tm_isdst = 0
};
return fputs(asctime(&value), stdout) == EOF ? 1 : 0;
}
Result
Sun Jan 1 12:34:56 2023
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.