Преобразование в строку

Простые типы / Дата и время

// For the current date take time(nullptr);
// a fixed moment keeps the output the same.
time_t moment = 1700000000;
struct tm date;
gmtime_r(&moment, &date);

char shortStyle[20];
strftime(shortStyle, sizeof shortStyle, "%D %I:%M %p", &date);
//shortStyle is "11/14/23 10:13 PM"

char customStyle[20];
strftime(customStyle, sizeof customStyle, "%Y-%m-%d", &date);
//customStyle is "2023-11-14"

char standardStyle[20];
strftime(standardStyle, sizeof standardStyle, "%F %T", &date);
//standardStyle is "2023-11-14 22:13:20"

char strFormat[32];
strftime(strFormat, sizeof strFormat, "Today %d %B, %A", &date);
//strFormat is "Today 14 November, Tuesday"

printf("shortStyle is %s\n", shortStyle);
printf("customStyle is %s\n", customStyle);
printf("standardStyle is %s\n", standardStyle);
printf("strFormat is %s\n", strFormat);