/// <summary> /// 英字元号取得 /// </summary> /// <param name="date">日付</param> /// <returns>英字元号(H:平成etc)</returns> public static string GetAlphabetEra(DateTime date) { System.Globalization.DateTimeFormatInfo formatInfo = null; System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("ja-JP"); formatInfo = culture.DateTimeFormat; formatInfo.Calendar = new System.Globalization.JapaneseCalendar(); int era = formatInfo.Calendar.GetEra(DateTime.Now); string eraText = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; for (int i = 0; i < eraText.Length; i++) { if (formatInfo.GetEra(eraText[i].ToString()) == era) { return(eraText[i].ToString()); } } return("H"); }
private void VerificationHelper(DateTimeFormatInfo info, string eraName, int expected) { int actual = info.GetEra(eraName); Assert.Equal(expected, actual); }
public void GetEra(DateTimeFormatInfo format, string eraName, int expected) { Assert.Equal(expected, format.GetEra(eraName)); }
private static int GetEra(__DTString str, DateTimeResult result, ref DateTimeFormatInfo dtfi) { int[] eras = dtfi.Calendar.Eras; if (eras != null) { String word = str.PeekCurrentWord(); int era; if ((era = dtfi.GetEra(word)) > 0) { str.Index += word.Length; return (era); } switch (dtfi.CultureID) { case 0x0411: // 0x0411 is the culture ID for Japanese. if (dtfi.Calendar.ID != Calendar.CAL_JAPAN) { // If the calendar for dtfi is Japanese, we have already // done the check above. No need to re-check again. GetJapaneseCalendarDTFI(); if ((era = m_jajpDTFI.GetEra(word)) > 0) { str.Index += word.Length; result.calendar = JapaneseCalendar.GetDefaultInstance(); dtfi = m_jajpDTFI; return (era); } } break; case 0x0404: // 0x0404 is the culture ID for Taiwan. if (dtfi.Calendar.ID != Calendar.CAL_TAIWAN) { GetTaiwanCalendarDTFI(); if ((era = m_zhtwDTFI.GetEra(word)) > 0) { str.Index += word.Length; result.calendar = TaiwanCalendar.GetDefaultInstance(); dtfi = m_zhtwDTFI; return (era); } } break; } } return (-1); }