Namespaces
Variants
Views
Actions

std::tm

From cppreference.com
< cpp‎ | chrono‎ | c
 
 
Utilities library
Language support
Type support (basic types, RTTI)
Library feature-test macros (C++20)
Dynamic memory management
Program utilities
Coroutine support (C++20)
Variadic functions
Debugging support
(C++26)
Three-way comparison
(C++20)
(C++20)(C++20)(C++20)
(C++20)(C++20)(C++20)
General utilities
Date and time
Function objects
Formatting library (C++20)
(C++11)
Relational operators (deprecated in C++20)
Integer comparison functions
(C++20)(C++20)(C++20)   
(C++20)
Swap and type operations
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
Common vocabulary types
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)
Elementary string conversions
(C++17)
(C++17)

 
 
 
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
seconds after the minute – [061](until C++11) [060](since C++11)[note 1]
(public member object)
int tm_min
minutes after the hour – [059]
(public member object)
int tm_hour
hours since midnight – [023]
(public member object)
int tm_mday
day of the month – [131]
(public member object)
int tm_mon
months since January – [011]
(public member object)
int tm_year
years since 1900
(public member object)
int tm_wday
days since Sunday – [06]
(public member object)
int tm_yday
days since January 1 – [0365]
(public member object)
int tm_isdst
Daylight Saving Time flag. The value is positive if DST is in effect, zero if not and negative if no information is available.
(public member object)
  1. Range allows for a positive leap second. Two leap seconds in the same minute are not allowed (the range [061] 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
seconds east of UTC
(public member object)
const char* tm_zone
timezone abbreviation
(public member object)

[edit] Example

#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 local time
(function) [edit]
converts time since epoch to calendar time expressed as Universal Coordinated Time
(function) [edit]