名稱空間
變體
操作

std::time_get<CharT,InputIt>::date_order, std::time_get<CharT,InputIt>::do_date_order

來自 cppreference.com
< cpp‎ | locale‎ | time get
 
 
 
 
 
定義於標頭檔案 <locale>
public:
dateorder date_order() const;
(1)
protected:
virtual dateorder do_date_order() const;
(2)
1) 公有成員函式,呼叫最派生類的保護虛擬成員函式 do_date_order
2) 返回 std::time_base::dateorder 型別的值,該值描述此區域設定使用的預設日期格式(get_date() 期望的格式,以及 std::strftime() 使用格式說明符 '%x' 生成的格式)。

有效值(繼承自 std::time_base)為

no_order 格式包含可變項(星期幾、儒略日等),或此函式未實現
dmy 日月年(歐洲區域設定)
mdy 月日年(美國區域設定)
ymd 年月日(亞洲區域設定)
ydm 年日月(罕見)

目錄

[編輯] 返回值

dateorder 型別的值。

[編輯] 注意

此函式是可選的,在任何情況下它都可能返回 no_order

[編輯] 示例

以下輸出是使用 clang (libc++) 獲得的。

#include <iostream>
#include <locale>
 
void show_date_order()
{
    std::time_base::dateorder d =
        std::use_facet<std::time_get<char>>(std::locale()).date_order();
    switch (d)
    {
        case std::time_base::no_order:
            std::cout << "no_order\n";
            break;
        case std::time_base::dmy:
            std::cout << "day, month, year\n";
            break;
        case std::time_base::mdy:
            std::cout << "month, day, year\n";
            break;
        case std::time_base::ymd:
            std::cout << "year, month, day\n";
            break;
        case std::time_base::ydm:
            std::cout << "year, day, month\n";
            break;
    }
}
 
int main()
{
    std::locale::global(std::locale("en_US.utf8"));
    std::cout << "In U.S. locale, the default date order is: ";
    show_date_order();
 
    std::locale::global(std::locale("ja_JP.utf8"));
    std::cout << "In Japanese locale, the default date order is: ";
    show_date_order();
 
    std::locale::global(std::locale("de_DE.utf8"));
    std::cout << "In German locale, the default date order is: ";
    show_date_order();
}

可能的輸出

In U.S. locale, the default date order is: month, day, year
In Japanese locale, the default date order is: year, month, day
In German locale, the default date order is: day, month, year

[編輯] 參閱

[virtual]
從輸入流中提取月、日、年
(虛擬保護成員函式) [編輯]
定義日期格式常量
(類) [編輯]