std::tm(3)
β¨ NAME β¨
std::tm β std::tm (yes bestie, that's the whole name, no cap). This is the std::tm(3) page from the C++ Standard Libary, and it's all about std::tm: a structure holding a calendar date and time broken down into its components. π
πΈ Synopsis πΈ
Defined in header <ctime>
struct tm;
Structure holding a calendar date and time broken down into its components. π¦
π«Ά Member objects π«Ά
int tm_secβ seconds after the minute. Range:[0, 61](until C++11), then[0, 60](since C++11)^[note 1]. (public member object)int tm_minβ minutes after the hour. Range:[0, 59]. (public member object)int tm_hourβ hours since midnight. Range:[0, 23]. (public member object)int tm_mdayβ day of the month. Range:[1, 31]. (public member object)int tm_monβ months since January. Range:[0, 11]. (public member object)int tm_yearβ years since 1900. (public member object)int tm_wdayβ days since Sunday. Range:[0, 6]. (public member object)int tm_ydayβ days since January 1. Range:[0, 365]. (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)
π Notes π
The Standard mandates only the presence of the aforementioned members in some order. The implementations usually add more data members to this structure. π«Ά
- β 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).
β¨ Example β¨
This is the code, bestie β run it if you want the vibe check:
// 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'
std::cout << "sizeof(std::tm) = " << sizeof(std::tm) << '\n'
<< "sum of sizes of standard members = "
<< sizeof(tm.tm_sec) +
sizeof(tm.tm_min) +
sizeof(tm.tm_hour) +
sizeof(tm.tm_mday) +
sizeof(tm.tm_mon) +
sizeof(tm.tm_year) +
sizeof(tm.tm_wday) +
sizeof(tm.tm_yday) +
sizeof(tm.tm_isdst) << '\n';
}
π₯ Possible output π₯
Like, maybe your machine prints this exactly:
Sat Jan 1 00:00:00 2022
sizeof(std::tm) = 56
sum of sizes of standard members = 36
π See also π
localtimeβ converts time since epoch to calendar time expressed as local time. (function)gmtimeβ converts time since epoch to calendar time expressed as Universal Coordinated Time. (function)- C documentation for
tmβ the C-side twin, iykyk. π
β¨ okay that's the page! source/version: http://cppreference.com; date: 2024.06.10; manual page: std::tm(3). slay and goodbye ππ
π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms