std::tm
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Date and time library
(C++11)
(C++20)
(C++20)
(C++11)
(C++11)
(C++11)
(C++20)
(C++20)
(C++20)
(C++11)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)
(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
Defined in header
<ctime>
struct tm;
Structure holding a calendar date and time broken down into its components.
Contents
[edit] Member objects
int tm_sec
[
0,
61]
(until C++11) [
0,
60]
(since C++11)[note 1] (public member object)
int tm_min
[
0,
59]
(public member object)
int tm_hour
[
0,
23]
(public member object)
int tm_mday
[
1,
31]
(public member object)
int tm_mon
[
0,
11]
(public member object)
int tm_year
(public member object)
int tm_wday
[
0,
6]
(public member object)
int tm_yday
[
0,
365]
(public member object)
int tm_isdst
(public member object)
- ↑ Range allows for a positive leap second. Two leap seconds in the same minute are not allowed (the range
[
0,
61]
was a defect introduced in C89 and corrected in C99).
[edit] Notes
BSD, GNU and musl C library support two additional members, which are standardized in POSIX.1-2024.
long tm_gmtoff
(public member object)
const char* tm_zone
(public member object)
[edit] Example
Run this code
#include <ctime> #include <iostream> int main() { std::tm tm{}; tm.tm_year = 2022 - 1900; tm.tm_mday = 1; std::mktime (&tm); std::cout << std::asctime (&tm); // note implicit trailing '\n' }
Possible output:
Sat Jan 1 00:00:00 2022
[edit] See also
converts time since epoch to calendar time expressed as Universal Coordinated Time
(function) [edit]
(function) [edit]
C documentation for tm