名稱空間
變體
操作

std::chrono::ambiguous_local_time

來自 cppreference.com
< cpp‎ | chrono
 
 
日期和時間庫
時間點
(C++11)
(C++20)
時長
(C++11)
時鐘
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
日間時間
(C++20)(C++20)
(C++20)(C++20)
(C++20)
日曆
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)
chrono I/O
(C++20)

時區
(C++20)
(C++20)
(C++20)
(C++20)
ambiguous_local_time
(C++20)
(C++20)
(C++20)
(C++20)
C風格日期和時間
 
定義於標頭檔案 <chrono>
class ambiguous_local_time;
(C++20 起)

定義一種物件型別,當嘗試將模稜兩可的 std::chrono::local_time 轉換為 std::chrono::sys_time 而未指定 std::chrono::choose(例如 choose::earliestchoose::latest)時,作為異常丟擲。

此異常由 std::chrono::time_zone::to_sys 以及呼叫它的函式(例如接受 std::chrono::local_timestd::chrono::zoned_time 的建構函式)丟擲。

cpp/error/exceptioncpp/error/runtime errorstd-chrono-ambiguous local time-inheritance.svg

繼承圖

目錄

[編輯] 成員函式

(建構函式)
構造異常物件
(公開成員函式)
operator=
替換異常物件
(公開成員函式)
what
返回解釋字串
(公開成員函式)

std::chrono::ambiguous_local_time::ambiguous_local_time

template< class Duration >

ambiguous_local_time( const std::chrono::local_time<Duration>& tp,

                      const std::chrono::local_info& i );
(1) (C++20 起)
ambiguous_local_time( const ambiguous_local_time& other ) noexcept;
(2) (C++20 起)

構造異常物件。

1) what() 返回的解釋字串等同於以下程式碼產生的 os.str()
std::ostringstream os;
os << tp << " is ambiguous.  It could be\n"
   << tp << ' ' << i.first.abbrev << " == "
   << tp - i.first.offset << " UTC or\n"
   << tp << ' ' << i.second.abbrev  << " == "
   << tp - i.second.offset  << " UTC";
如果 i.result != std::chrono::local_info::ambiguous,則行為未定義。
2) 複製建構函式。如果 *thisother 都具有動態型別 std::chrono::ambiguous_local_time,則 std::strcmp(what(), other.what()) == 0

引數

tp - 嘗試轉換的時間點
i - 描述轉換結果的 std::chrono::local_info
其他 - 另一個要複製的 ambiguous_local_time

異常

可能丟擲 std::bad_alloc

注意

因為不允許複製派生自 std::exception 的標準庫類丟擲異常,所以此訊息通常作為單獨分配的引用計數字符串內部儲存。

std::chrono::ambiguous_locale_time::operator=

ambiguous_locale_time& operator=( const ambiguous_locale_time& other ) noexcept;
(C++20 起)

other 的內容賦值。如果 *thisother 都具有動態型別 std::chrono::ambiguous_locale_time,則賦值後 std::strcmp(what(), other.what()) == 0

引數

其他 - 用於賦值的另一個異常物件

返回值

*this

std::chrono::ambiguous_locale_time::what

virtual const char* what() const noexcept;
(C++20 起)

返回解釋字串。

返回值

指向實現定義的空終止字串的指標,其中包含解釋性資訊。該字串適合轉換為 std::wstring 並顯示。保證該指標至少在獲取它的異常物件被銷燬之前,或在異常物件上呼叫非 const 成員函式(例如複製賦值運算子)之前有效。

在常量求值期間,返回的字串使用普通字面量編碼進行編碼。

(C++26 起)

注意

允許但不要求實現重寫 what()

繼承自 std::runtime_error


繼承自 std::exception

成員函式

銷燬異常物件
(std::exception 的虛公共成員函式) [編輯]
[virtual]
返回解釋字串
(std::exception 的虛公共成員函式) [編輯]

[編輯] 另請參閱

報告本地時間不存在時丟擲的異常
(類) [編輯]