Share via


time_zone 클래스

A time_zone 는 특정 지리적 영역에 대한 표준 시간대를 나타냅니다. 각 영역에 대한 표준 시간대 규칙의 전체 기록이 있으므로 표준 시간대에 대한 규칙이 현재와 다른 날짜로 시간을 변환하면 시간 변환이 정확합니다.

구문

class time_zone;  // Since C++20

설명

라이브러리는 <chrono> 표준 시간대 데이터베이스 초기화의 일부로 개체를 만듭니다 time_zone . 생성된 개체에 대한 액세스를 제공합니다 const .

개체를 time_zone 생성하거나 복사할 수 없으며 기본 이동 생성자 또는 기본 이동 할당 연산자를 사용하면 정의되지 않은 동작이 발생합니다.

인스턴스를 가져오는 방법은 다음과 같습니다.time_zone

const auto& timeZoneDatabase = get_tzdb(); // initialize the time zone database
const auto& currentZone = timeZoneDatabase.current_zone();

Microsoft C++는 Visual Studio 2019 버전 16.10부터 클래스를 지원 time_zone 합니다. 클래스는 time_zone C++20 기능입니다. /std:c++latest 컴파일러 옵션이 필요합니다.

멤버

공용 멤버 함수 및 함수 템플릿

이름 설명
get_info 또는 이 항목 sys_infolocal_info 에 대해 가져옵니다 time_zone.
name time_zone이름을 가져옵니다.
to_local 이 경우 a sys_time 를 a local_time 로 변환 time_zone합니다.
to_sys 이 경우 a local_time 를 a sys_time 로 변환 time_zone합니다.

요구 사항

헤더<chrono>:

표준 시간대 데이터는 Windows 10 버전 1903/19H1 이상 및 Windows Server 2022 이상에서만 사용할 수 있습니다.

네임스페이스:std::chrono

get_info

함수 템플릿 get_info 에는 이를 가져오는 sys_infolocal_info 두 개의 오버로드가 time_zone있습니다.

template<class Duration>
sys_info get_info(const sys_time<Duration>& st) const;  // Since C++20
    
template<class Duration>
local_info get_info(const local_time<Duration>& lt) const;  // Since C++20

매개 변수

Duration
duration 또는 local_time 매개 변수의 sys_time 클래스입니다.

st
sys_time 결과를 가져오는 데 사용되는 시간 지점입니다sys_info.

lt
local_time 결과를 가져오는 데 사용되는 시간 지점입니다local_info.

반환 값

get_info 시간 지점을 st사용하는 sys_time 함수 템플릿에서 범위 [i.begin, i.end)내의 sys_info 개체를 반환합니다 ist.

get_info 시간 지점을 lt사용하는 local_time 함수 템플릿에서 개체를 local_info 반환합니다.

설명

Microsoft C++는 Visual Studio 2019 버전 16.10부터 지원합니다 time_zone::get_info . 이 함수는 컴파일러 옵션이 필요한 /std:c++latest C++20 기능입니다.

name

time_zone이름을 가져옵니다.

string_view name() const noexcept;  // Since C++20

반환 값

표준 시간대의 이름을 .로 string_view반환합니다.

설명

Microsoft C++는 Visual Studio 2019 버전 16.10부터 지원합니다 time_zone::name .

to_local

함수 템플릿 to_local 은 이 time_zone함수에서 a sys_timelocal_time 변환합니다.

template<class Duration>
local_time<common_type_t<Duration, seconds>>
to_local(const sys_time<Duration>& st) const;  // Since C++20

매개 변수

Duration
duration 또는 local_time 매개 변수의 sys_time 클래스입니다.

st
sys_time 결과를 가져오는 데 사용되는 시간 지점입니다sys_info.

반환 값

to_local는 이 local_timetime_zone에 연결된 st 값을 반환합니다.

설명

Microsoft C++는 Visual Studio 2019 버전 16.10부터 지원합니다 time_zone::to_local . 이 함수는 컴파일러 옵션이 필요한 /std:c++latest C++20 기능입니다.

예: 변환 sys_timelocal_time

// compile using: /std:c++latest
#include <iostream>
#include <chrono>

using namespace std::chrono;

int main()
{
    const auto& timeZoneDatabase = get_tzdb();
    const auto& currentZone = timeZoneDatabase.current_zone();
    local_time<system_clock::duration> lt = currentZone->to_local(system_clock::now());

    std::cout << "local_time: " << lt << "\n";
   
    return 0;
}
local_time: 2021-09-08 15:15:53.1830646

to_sys

함수 템플릿 to_sys 에는 이 함수에서 a local_time 로 변환하는 두 개의 오버로드가 time_zonesys_time 있습니다.

template<class Duration>
sys_time<common_type_t<Duration, seconds>>
to_sys(const local_time<Duration>& lt) const;  // Since C++20

template<class Duration>
sys_time<common_type_t<Duration, seconds>>
to_sys(const local_time<Duration>& lt, choose z) const;  // Since C++20

매개 변수

Duration
duration 매개 변수의 클래스입니다local_time.

lt
local_time 변환할 시간 지점입니다.

z
값 또는 choose::earliestchoose::latest. 그렇지 않으면 모호한 결과를 해결하는 데 사용됩니다.

반환 값

to_syssys_time 는 최소한 1만큼 괜찮은 seconds값을 반환합니다. 인수 lt 의 정밀도가 더 세밀하면 더 좋습니다. 반환 sys_time 되는 UTC는 이 time_zone 규칙에 따라 동일합니다 lt .

한 매개 변수 오버로드는 변환 lt 이 모호한 경우 예외를 sys_time throw하고nonexistent_local_time, 현지 시간 지점이 존재하지 않는 현지 시간 지점을 나타내는 경우 예외를 throw ambiguous_local_time 합니다. 표준 시간 전환에 일광 절약 시간제 동안 모호성이 발생할 수 있습니다. 동일한 현지 시간 지점의 두 인스턴스가 하루에 발생할 수 있습니다. 존재하지 않는 현지 시간 포인트는 표준 시간에서 일광 절약 시간으로의 전환 시간을 나타냅니다.

두 매개 변수 오버로드는 이러한 경우 예외를 throw하지 않습니다. 변환 ltsys_time 이 모호한 to_sys 경우 이전 sys_timez if is choose::earliest를 반환하고 이후 sys_time 의 경우 zchoose::latest를 반환합니다. lt 두 UTC 시간 포인트 사이에 존재하지 않는 시간을 나타내는 경우 두 UTC 시간 지점이 같으므로 to_sys 해당 UTC 시간 지점을 반환합니다.

설명

Microsoft C++는 Visual Studio 2019 버전 16.10부터 지원합니다 time_zone::to_sys . 이 함수는 컴파일러 옵션이 필요한 /std:c++latest C++20 기능입니다.

예: 변환 local_timesys_time

// compile using: /std:c++latest
#include <iostream>
#include <chrono>

using namespace std::chrono;

int main()
{
    const auto& timeZoneDatabase = get_tzdb();
    const auto& currentZone = timeZoneDatabase.current_zone();

    auto st = currentZone->to_sys(local_days{2021y/September/15d}+16h+45min, choose::earliest);

    std::cout << "sys_time: " << st << "\n";
   
    return 0;
}
sys_time: 2021-09-15 23:45:00.0000000

참고 항목

<chrono>
헤더 파일 참조