time_point_time_point_cast

time_point_time_point_cast (시간점 단위 변환)

std::chrono::time_point_cast는 시간점의 기간을 다른 단위로 변환해요.

출처: cppreference

본문

std::chrono::time_point_cast<chrono> 헤더에 정의된 함수 템플릿이에요.

template< class ToDuration, class Clock, class Duration >
constexpr std::chrono::time_point<Clock, ToDuration>
    time_point_cast( const std::chrono::time_point<Clock, Duration>& t );

시간점 t의 기간을 ToDuration으로 변환한 새 시간점을 반환해요. 변환은 std::chrono::duration_cast와 마찬가지로 잘라내기로 처리돼요. ToDurationstd::chrono::duration의 특수화일 때만 오버로드 해석에 참여해요.

예제 (Example)

#include <chrono>
#include <iostream>

int main()
{
    using namespace std::chrono;
    sys_time<milliseconds> tp{milliseconds{2500}};
    auto casted = time_point_cast<seconds>(tp);
    std::cout << casted.time_since_epoch().count() << '\n'; // 2
}

더 알아보기 (Learn more)

cppreference