DateTimeFormatInfo.GetEra メソッド
指定した時代 (年号) を表す整数を返します。
Public Function GetEra( _
ByVal eraName As String _) As Integer
[C#]
public int GetEra(stringeraName);
[C++]
public: int GetEra(String* eraName);
[JScript]
public function GetEra(
eraName : String) : int;
パラメータ
- eraName
時代 (年号) の名前を格納している文字列。
戻り値
eraName が有効な場合は時代 (年号) を表す整数。それ以外の場合は -1。
例外
例外の種類 | 条件 |
---|---|
ArgumentNullException | eraName が null 参照 (Visual Basic では Nothing) です。 |
解説
時代 (年号) 名とは、固定された時点または出来事から計算された期間を示すために暦で使用する名前です。たとえば、"A.D." または "C.E." は、グレゴリオ暦の現在の時代 (年号) です。
eraName との比較では、大文字と小文字は区別されません。たとえば"A.D." は "a.d." と同じです。
DateTimeFormatInfo.Calendar で GregorianCalendar が選択されており、カルチャが時代 (年号) 名として "A.D." を使用する場合にだけ、 GetEra は、時代 (年号) 名の省略形で使用される句読点を無視します。つまり、"A.D." は "AD" と解釈されます。
GetEra は、 GetEraName が返す時代 (年号) の完全名および GetAbbreviatedEraName が返す時代 (年号) の省略名と、 eraName を比較します。
使用例
[Visual Basic, C#, C++] 暦がグレゴリオ暦で、カルチャが時代 (年号) 名 "A.D." を使用する場合にだけ、 DateTimeFormatInfo が時代 (年号) 名に含まれている句読点を無視するコードの例を次に示します。
Imports System
Imports System.Globalization
Public Class SamplesGregorianCalendar
Public Shared Sub Main()
' Creates strings with punctuation and without.
Dim strADPunc As [String] = "A.D."
Dim strADNoPunc As [String] = "AD"
Dim strCEPunc As [String] = "C.E."
Dim strCENoPunc As [String] = "CE"
' Calls DTFI.GetEra for each culture that uses GregorianCalendar as the default calendar.
Console.WriteLine(" ----- AD ----- ----- CE -----")
Console.WriteLine("CULTURE PUNC NO PUNC PUNC NO PUNC CALENDAR")
Dim myCI As CultureInfo
For Each myCI In CultureInfo.GetCultures(CultureTypes.SpecificCultures)
Console.Write("{0,-12}", myCI)
Console.Write("{0,-7}{1,-9}", myCI.DateTimeFormat.GetEra(strADPunc), myCI.DateTimeFormat.GetEra(strADNoPunc))
Console.Write("{0,-7}{1,-9}", myCI.DateTimeFormat.GetEra(strCEPunc), myCI.DateTimeFormat.GetEra(strCENoPunc))
Console.Write("{0}", myCI.Calendar)
Console.WriteLine()
Next myCI
End Sub 'Main
End Class 'SamplesGregorianCalendar
'This code produces the following output. This output has been cropped for brevity.
'
' ----- AD ----- ----- CE -----
'CULTURE PUNC NO PUNC PUNC NO PUNC CALENDAR
'ar-SA -1 -1 -1 -1 System.Globalization.HijriCalendar
'ar-IQ 1 1 -1 -1 System.Globalization.GregorianCalendar
'ar-EG 1 1 -1 -1 System.Globalization.GregorianCalendar
'ar-LY 1 1 -1 -1 System.Globalization.GregorianCalendar
'ar-DZ 1 1 -1 -1 System.Globalization.GregorianCalendar
'ar-MA 1 1 -1 -1 System.Globalization.GregorianCalendar
'ar-TN 1 1 -1 -1 System.Globalization.GregorianCalendar
'ar-OM 1 1 -1 -1 System.Globalization.GregorianCalendar
'ar-YE 1 1 -1 -1 System.Globalization.GregorianCalendar
'ar-SY 1 1 -1 -1 System.Globalization.GregorianCalendar
'ar-JO 1 1 -1 -1 System.Globalization.GregorianCalendar
'ar-LB 1 1 -1 -1 System.Globalization.GregorianCalendar
'ar-KW 1 1 -1 -1 System.Globalization.GregorianCalendar
'ar-AE 1 1 -1 -1 System.Globalization.GregorianCalendar
'ar-BH 1 1 -1 -1 System.Globalization.GregorianCalendar
'ar-QA 1 1 -1 -1 System.Globalization.GregorianCalendar
'bg-BG 1 1 -1 -1 System.Globalization.GregorianCalendar
'ca-ES -1 -1 -1 -1 System.Globalization.GregorianCalendar
'zh-TW -1 -1 -1 -1 System.Globalization.GregorianCalendar
'zh-CN -1 -1 -1 -1 System.Globalization.GregorianCalendar
'zh-HK -1 -1 -1 -1 System.Globalization.GregorianCalendar
'zh-SG 1 1 -1 -1 System.Globalization.GregorianCalendar
'zh-MO 1 1 -1 -1 System.Globalization.GregorianCalendar
'cs-CZ -1 -1 -1 -1 System.Globalization.GregorianCalendar
'da-DK 1 1 -1 -1 System.Globalization.GregorianCalendar
[C#]
using System;
using System.Globalization;
public class SamplesGregorianCalendar {
public static void Main() {
// Creates strings with punctuation and without.
String strADPunc = "A.D.";
String strADNoPunc = "AD";
String strCEPunc = "C.E.";
String strCENoPunc = "CE";
// Calls DTFI.GetEra for each culture that uses GregorianCalendar as the default calendar.
Console.WriteLine( " ----- AD ----- ----- CE -----" );
Console.WriteLine( "CULTURE PUNC NO PUNC PUNC NO PUNC CALENDAR" );
foreach ( CultureInfo myCI in CultureInfo.GetCultures( CultureTypes.SpecificCultures ) ) {
Console.Write( "{0,-12}", myCI );
Console.Write( "{0,-7}{1,-9}", myCI.DateTimeFormat.GetEra( strADPunc ), myCI.DateTimeFormat.GetEra( strADNoPunc ) );
Console.Write( "{0,-7}{1,-9}", myCI.DateTimeFormat.GetEra( strCEPunc ), myCI.DateTimeFormat.GetEra( strCENoPunc ) );
Console.Write( "{0}", myCI.Calendar );
Console.WriteLine();
}
}
}
/*
This code produces the following output. This output has been cropped for brevity.
----- AD ----- ----- CE -----
CULTURE PUNC NO PUNC PUNC NO PUNC CALENDAR
ar-SA -1 -1 -1 -1 System.Globalization.HijriCalendar
ar-IQ 1 1 -1 -1 System.Globalization.GregorianCalendar
ar-EG 1 1 -1 -1 System.Globalization.GregorianCalendar
ar-LY 1 1 -1 -1 System.Globalization.GregorianCalendar
ar-DZ 1 1 -1 -1 System.Globalization.GregorianCalendar
ar-MA 1 1 -1 -1 System.Globalization.GregorianCalendar
ar-TN 1 1 -1 -1 System.Globalization.GregorianCalendar
ar-OM 1 1 -1 -1 System.Globalization.GregorianCalendar
ar-YE 1 1 -1 -1 System.Globalization.GregorianCalendar
ar-SY 1 1 -1 -1 System.Globalization.GregorianCalendar
ar-JO 1 1 -1 -1 System.Globalization.GregorianCalendar
ar-LB 1 1 -1 -1 System.Globalization.GregorianCalendar
ar-KW 1 1 -1 -1 System.Globalization.GregorianCalendar
ar-AE 1 1 -1 -1 System.Globalization.GregorianCalendar
ar-BH 1 1 -1 -1 System.Globalization.GregorianCalendar
ar-QA 1 1 -1 -1 System.Globalization.GregorianCalendar
bg-BG 1 1 -1 -1 System.Globalization.GregorianCalendar
ca-ES -1 -1 -1 -1 System.Globalization.GregorianCalendar
zh-TW -1 -1 -1 -1 System.Globalization.GregorianCalendar
zh-CN -1 -1 -1 -1 System.Globalization.GregorianCalendar
zh-HK -1 -1 -1 -1 System.Globalization.GregorianCalendar
zh-SG 1 1 -1 -1 System.Globalization.GregorianCalendar
zh-MO 1 1 -1 -1 System.Globalization.GregorianCalendar
cs-CZ -1 -1 -1 -1 System.Globalization.GregorianCalendar
da-DK 1 1 -1 -1 System.Globalization.GregorianCalendar
*/
[C++]
#using <mscorlib.dll>
using namespace System;
using namespace System::Globalization;
using namespace System::Collections;
int main()
{
// Creates strings with punctuation and without.
String * strADPunc = S"A.D.";
String * strADNoPunc = S"AD";
String * strCEPunc = S"C.E.";
String * strCENoPunc = S"CE";
// Calls DTFI::GetEra for each culture that uses GregorianCalendar as the default calendar.
Console::WriteLine(S" ----- AD ----- ----- CE -----");
Console::WriteLine(S"CULTURE PUNC NO PUNC PUNC NO PUNC CALENDAR");
IEnumerator* en =
CultureInfo::GetCultures(CultureTypes::SpecificCultures)->GetEnumerator();
while(en->MoveNext()){
CultureInfo* myCI = __try_cast<CultureInfo*>(en->Current);
Console::Write(S"{0, -12}", myCI);
Console::Write(S"{0,-7}{1,-9}", __box(myCI -> DateTimeFormat ->GetEra(strADPunc)),
__box(myCI -> DateTimeFormat -> GetEra(strADNoPunc)));
Console::Write(S"{0, -7}{1, -9}",
__box(myCI -> DateTimeFormat -> GetEra(strCEPunc)),
__box(myCI -> DateTimeFormat -> GetEra(strCENoPunc)));
Console::Write(S"{0}", myCI -> Calendar);
Console::WriteLine();
}
}
/*
This code produces the following output. This output has been cropped for brevity.
----- AD ----- ----- CE -----
CULTURE PUNC NO PUNC PUNC NO PUNC CALENDAR
ar-SA -1 -1 -1 -1 System.Globalization.HijriCalendar
ar-IQ 1 1 -1 -1 System.Globalization.GregorianCalendar
ar-EG 1 1 -1 -1 System.Globalization.GregorianCalendar
ar-LY 1 1 -1 -1 System.Globalization.GregorianCalendar
ar-DZ 1 1 -1 -1 System.Globalization.GregorianCalendar
ar-MA 1 1 -1 -1 System.Globalization.GregorianCalendar
ar-TN 1 1 -1 -1 System.Globalization.GregorianCalendar
ar-OM 1 1 -1 -1 System.Globalization.GregorianCalendar
ar-YE 1 1 -1 -1 System.Globalization.GregorianCalendar
ar-SY 1 1 -1 -1 System.Globalization.GregorianCalendar
ar-JO 1 1 -1 -1 System.Globalization.GregorianCalendar
ar-LB 1 1 -1 -1 System.Globalization.GregorianCalendar
ar-KW 1 1 -1 -1 System.Globalization.GregorianCalendar
ar-AE 1 1 -1 -1 System.Globalization.GregorianCalendar
ar-BH 1 1 -1 -1 System.Globalization.GregorianCalendar
ar-QA 1 1 -1 -1 System.Globalization.GregorianCalendar
bg-BG 1 1 -1 -1 System.Globalization.GregorianCalendar
ca-ES -1 -1 -1 -1 System.Globalization.GregorianCalendar
zh-TW -1 -1 -1 -1 System.Globalization.GregorianCalendar
zh-CN -1 -1 -1 -1 System.Globalization.GregorianCalendar
zh-HK 1 1 -1 -1 System.Globalization.GregorianCalendar
zh-SG 1 1 -1 -1 System.Globalization.GregorianCalendar
zh-MO 1 1 -1 -1 System.Globalization.GregorianCalendar
cs-CZ -1 -1 -1 -1 System.Globalization.GregorianCalendar
da-DK 1 1 -1 -1 System.Globalization.GregorianCalendar
*/
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard
参照
DateTimeFormatInfo クラス | DateTimeFormatInfo メンバ | System.Globalization 名前空間 | GetEraName | Calendar