Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
std::chrono...from_time_t(3)  C++ Standard Libary std::chrono...from_time_t(3)

NAME
       std::chrono::system_clock::from_time_t	     -	     std::chrono::sys-
       tem_clock::from_time_t

Synopsis
	  static      std::chrono::system_clock::time_point	  from_time_t(
       std::time_t  (since C++11)
	  t ) noexcept;

	  Converts  t to a time	point type, using the coarser precision	of the
       two types.

	  If time_point	has lower  precision,  it  is  implementation  defined
       whether the value is
	  rounded or truncated.

Parameters
	  t - std::time_t value	to convert

Return value
	  A  value  of type std::chrono::system_clock::time_point representing
       t.

Example
       // Run this code

	#include <iostream>
	#include <ctime>
	#include <chrono>
	#include <thread>

	int main()
	{
	    using namespace std::chrono_literals;

	    const std::time_t t	= std::time(nullptr); // usually has  "1  sec-
       ond" 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 to std::time_t
	  [static]  (public static member function)

http://cppreference.com		  2022.07.31	  std::chrono...from_time_t(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=std::chrono::system_clock::from_time_t&sektion=3&manpath=FreeBSD+Ports+15.0>

home | help