std::time(3)
π
std::time(3) β std::time π
okay bestie, welcome to the std::time(3) page from the C++ Standard Library docs β¨ this one is short, iconic, and very βwhat time is it actually thoβ energy π°οΈπ
πΈ NAME πΈ
std::time β std::time (yes, the NAME section is just doing its thing, and we respect it π
)
β¨ Synopsis β¨
Defined in header <ctime>:
std::time_t time( std::time_t* arg );
Returns the current calendar time encoded as a std::time_t object, and also stores it in the object pointed to by arg, unless arg is a null pointer. no cap π«Ά
π Parameters π
argβ pointer to astd::time_tobject to store the time, or a null pointer π
π Return value π
Current calendar time encoded as std::time_t object on success, (std::time_t)(-1) on error. If arg is not null, the return value is also stored in the object pointed to by arg. periodt π
π§ Notes π§
Okay so the encoding of calendar time in std::time_t is unspecified, but most systems conform to the POSIX specification and return a value of integral type holding 86400 times the number of calendar days since the Epoch plus the number of seconds that have passed since the last midnight UTC π
Most notably, POSIX time does not (and can not) take leap seconds into account, so that this integral value is not equal to the number of S.I. seconds that have passed since the epoch, but rather is reduced with the number of leap seconds that have occurred since the epoch π
Implementations in which std::time_t is a 32-bit signed integer (many historical implementations) fail in the year 2038. big yikes π
π Example π
// Run this code
#include <ctime>
#include <iostream>
int main()
{
std::time_t result = std::time(nullptr);
std::cout << std::asctime(std::localtime(&result))
<< result << " seconds since the Epoch\n";
}
β Possible output β
Wed Sep 21 10:27:52 2011
1316615272 seconds since the Epoch
π₯ See also π₯
timespec_getβ returns the calendar time in seconds and nanoseconds based on a given time base (C++17) (function) β±οΈ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) πsystem_clockβ wall clock time from the system-wide realtime clock (C++11) (class) π- C documentation for
timeπ«Ά
xoxo, http://cppreference.com π 2024.06.10 π std::time(3) πβ¨
π¦ 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