C++ iomanip put_time() Function
Example
Print a date in the format day.month.year:
tm date = {};
date.tm_year = 2026 - 1900;
date.tm_mon = 10; // November (months start at 0)
date.tm_mday = 5;
cout << put_time(&date, "%d.%m.%Y");
Definition and Usage
The put_time() function prints the date and time from a tm structure, in the format you choose.
The format uses the same codes as strftime(), like %d for the day, %m for the month and %Y for the year.
The put_time function is defined in the <iomanip> header file.
Tip: Learn more about dates in the Date chapter.
Syntax
put_time(const tm* time, const char* format)
Parameter Values
| Parameter | Description |
|---|---|
| time | Required. A pointer to the tm structure with the date and time. |
| format | Required. A text with format codes, like "%d.%m.%Y". |
Technical Details
| Returns: | A manipulator that you use with <<. |
|---|