2017-12-25 21 views
1

이 위의 코드는 '나쁜 캐스트'예외가 발생 How to get the current time zone?Windows의 현재 부스트 시간대를 얻는 방법은 무엇입니까?

#include <ctime> 
tzset(); 
time_zone_ptr zone(new posix_time_zone(tzname[localtime(0)->tm_isdst])); 

유사하다. tzname 또는 GetTimeZoneInformation의 시간대는 부스트 시간대에서 허용되지 않는 '중국 표준시'과 같은 문자열입니다.

기본 문제를 쉽게 해결할 수 있습니까? Howard Hinnant's time zone library를 사용

답변

1

, 다음은 Windows에서 현재 IANA time zone 이름을 인쇄합니다 :

#include "date/tz.h" 
#include <iostream> 

int 
main() 
{ 
    std::cout << date::current_zone()->name() << '\n'; 
} 

일부 installation는 Windows에서 필요합니다. 나를 위해 위의 프로그램 출력 :

America/New_York 

implementationGetDynamicTimeZoneInformation를 사용하여 현재 Windows 표준 시간대를 조회 한 다음 IANA time zone 이름으로 기본 Windows 표준 시간대 이름에서 매핑 this Unicode mapping를 사용합니다.