std::chrono...from_time_t(3)
πΈ NAME πΈ
okay bestie, welcome to the C++ Standard Libary page for std::chrono::system_clock::from_time_t π
std::chrono::system_clock::from_time_t β std::chrono::system_clock::from_time_t
β¨ Synopsis β¨
The signature, (since C++11) girlies:
static std::chrono::system_clock::time_point from_time_t( std::time_t t ) noexcept;
So what it does: it converts t to a time point type, using the coarser precision of the two types. And yes, it's noexcept β no throwing drama here π
If time_point has lower precision, it is implementation defined whether the value is rounded or truncated. That's the rule, no cap π
π Parameters π
tβ thestd::time_tvalue to convert π«Ά
π¦ Return value π¦
A value of type std::chrono::system_clock::time_point representing t. periodt β¨
π Example π
Run this code, bestie:
// Run this code
#include <chrono>
#include <ctime>
#include <iostream>
#include <thread>
int main()
{
using namespace std::chrono_literals;
const std::time_t t = std::time(nullptr); // usually has "1 second"
precision
const auto from = std::chrono::system_clock::from_time_t(t);
std::this_thread::sleep_for(500ms);
const auto diff = std::chrono::system_clock::now() - from;
std::cout << diff << " ("
<< std::chrono::round<std::chrono::milliseconds>(diff)
<< ")\n";
}
Possible output:
987654321ns (987ms)
π See also π
to_time_tβ converts a system clock time point tostd::time_t;[static](public static member function) π
mwah π source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::chrono...from_time_t(3) β bye bestie π
π¦ 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