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

FreeBSD Manual Pages

  
 
  

home | help
std::chrono...::time_point(3) C++ Standard Libarystd::chrono...::time_point(3)

NAME
       std::chrono::time_point::time_point				     -
       std::chrono::time_point::time_point

Synopsis
						(since C++11)
	  time_point();				(constexpr since
						C++14)
	  explicit time_point( const				 (since	C++11)
	  duration& d );		(1)			 (constexpr
								 since C++14)
	  template<	   class	 Duration2	   >		   (2)
       (since C++11)
	  time_point(		    const				   (3)
       (constexpr
	  time_point<Clock,					   Duration2>&
       since C++14)
	  t );

	  Constructs  a	 new  time_point  from	one  of	 several optional data
       sources.

	  1)  Default  constructor,  creates  a	 time_point  representing  the
       Clock's epoch (i.e.,
	  time_since_epoch() is	zero).
	  2) Constructs	a time_point at	Clock's	epoch plus d.
	  3)  Constructs  a  time_point	by converting t	to duration. This con-
       structor	only
	  participates in overload resolution if Duration2 is implicitly  con-
       vertible	to
	  duration.

Parameters
	  d - a	duration to copy from
	  t - a	time_point to convert from

Example
       // Run this code

	#include <chrono>
	#include <iostream>

	using Clock = std::chrono::steady_clock;
	using TimePoint	= std::chrono::time_point<Clock>;

	void print_ms(const TimePoint& point)
	{
	    using Ms = std::chrono::milliseconds;
	    const Clock::duration since_epoch =	point.time_since_epoch();
	    std::cout << std::chrono::duration_cast<Ms>(since_epoch) <<	'\n';
	}

	int main()
	{
	    const TimePoint default_value = TimePoint(); // (1)
	    print_ms(default_value); //	0ms

	    const   Clock::duration   duration_4_seconds  =  std::chrono::sec-
       onds(4);
	    const TimePoint time_point_4_seconds(duration_4_seconds); // (2)
	    // 4 seconds from start of epoch
	    print_ms(time_point_4_seconds); // 4000ms

	    const TimePoint time_point_now = Clock::now(); // (3)
	    print_ms(time_point_now); // 212178842ms
	}

Possible output:
	0ms
	4000ms
	212178842ms

See also
	  constructor	constructs new duration
			(public	  member   function   of    std::chrono::dura-
       tion<Rep,Period>)
	  duration_cast	 converts a duration to	another, with a	different tick
       interval
	  (C++11)	(function template)

http://cppreference.com		  2024.06.10	 std::chrono...::time_point(3)

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

home | help