DateTimeFormatInfo.Calendar DateTimeFormatInfo.Calendar DateTimeFormatInfo.Calendar DateTimeFormatInfo.Calendar Property

定義

現在のカルチャで使用する暦を取得または設定します。Gets or sets the calendar to use for the current culture.

public:
 property System::Globalization::Calendar ^ Calendar { System::Globalization::Calendar ^ get(); void set(System::Globalization::Calendar ^ value); };
public System.Globalization.Calendar Calendar { get; set; }
member this.Calendar : System.Globalization.Calendar with get, set
Public Property Calendar As Calendar

プロパティ値

現在のカルチャで使用する暦。The calendar to use for the current culture. InvariantInfo の既定値は GregorianCalendar オブジェクトです。The default for InvariantInfo is a GregorianCalendar object.

例外

プロパティが null に設定されています。The property is being set to null.

プロパティが、現在のカルチャでは有効でない Calendar オブジェクトに設定されています。The property is being set to a Calendar object that is not valid for the current culture.

このプロパティが設定されていますが、DateTimeFormatInfo オブジェクトは読み取り専用です。The property is being set and the DateTimeFormatInfo object is read-only.

次の例では、定義、ChangeCalendar現在の暦で既にある場合を除き、またはカルチャでサポートされていない場合に指定した暦のカルチャの現在の暦を変更する方法。The following example defines a ChangeCalendar method that changes a culture's current calendar to a specified calendar unless it is already the current calendar or if it is not supported by the culture. メソッドを呼び出すコードをインスタンス化、CultureInfoアラビア語 (エジプト) カルチャを表す、最初に日本語のカレンダーにその暦を変更しようとするオブジェクト。The code that calls the method instantiates a CultureInfo object that represents the Arabic (Egypt) culture and first attempts to change its calendar to the Japanese calendar. メソッドを使用すると、和暦がサポートされていないため、カルチャの暦は変わりません。Because the Japanese calendar is not supported, the method makes not change the culture's calendar. ただし、ため、um のメンバーであるウムアルクラ暦、CultureInfo.OptionalCalendarsコレクション、メソッドが成功現在の暦を行う、AR-EG カルチャします。However, because the Umm al-Qura calendar is a member of the CultureInfo.OptionalCalendars collection, the method does succeed in making it the current calendar for the ar-EG culture.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      CultureInfo ci = CultureInfo.CreateSpecificCulture("ar-EG");
      Console.WriteLine("The current calendar for the {0} culture is {1}",
                        ci.Name, 
                        CalendarUtilities.ShowCalendarName(ci.DateTimeFormat.Calendar));

      CalendarUtilities.ChangeCalendar(ci, new JapaneseCalendar());
      Console.WriteLine("The current calendar for the {0} culture is {1}",
                        ci.Name, 
                        CalendarUtilities.ShowCalendarName(ci.DateTimeFormat.Calendar));
      
      CalendarUtilities.ChangeCalendar(ci, new UmAlQuraCalendar());
      Console.WriteLine("The current calendar for the {0} culture is {1}",
                        ci.Name, 
                        CalendarUtilities.ShowCalendarName(ci.DateTimeFormat.Calendar));
   }
}

public class CalendarUtilities
{
   private Calendar newCal;
   private bool isGregorian;
   
   public static void ChangeCalendar(CultureInfo ci, Calendar cal)
   {
      CalendarUtilities util = new CalendarUtilities(cal);
      
      // Is the new calendar already the current calendar?
      if (util.CalendarExists(ci.DateTimeFormat.Calendar))
         return;

      // Is the new calendar supported?
      if (Array.Exists(ci.OptionalCalendars, util.CalendarExists))
         ci.DateTimeFormat.Calendar = cal;
   }
   
   private CalendarUtilities(Calendar cal)
   {
      newCal = cal;
      
      // Is the new calendar a Gregorian calendar?
      isGregorian = cal.GetType().Name.Contains("Gregorian");
   }
   
   private bool CalendarExists(Calendar cal)
   {
      if (cal.ToString() == newCal.ToString()) {
         if (isGregorian) {
            if (((GregorianCalendar) cal).CalendarType == 
               ((GregorianCalendar) newCal).CalendarType)
               return true;
         }
         else {
            return true;
         }
      }
      return false;
   }

   public static string ShowCalendarName(Calendar cal)
   {
      string calName = cal.ToString().Replace("System.Globalization.", "");
      if (cal is GregorianCalendar)
         calName += ", Type " + ((GregorianCalendar) cal).CalendarType.ToString();

      return calName; 
   }
}
// The example displays the following output:
//    The current calendar for the ar-EG culture is GregorianCalendar, Type Localized
//    The current calendar for the ar-EG culture is GregorianCalendar, Type Localized
//    The current calendar for the ar-EG culture is UmAlQuraCalendar
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim ci As CultureInfo = CultureInfo.CreateSpecificCulture("ar-EG")
      Console.WriteLine("The current calendar for the {0} culture is {1}",
                        ci.Name, 
                        CalendarUtilities.ShowCalendarName(ci.DateTimeFormat.Calendar))

      CalendarUtilities.ChangeCalendar(ci, New JapaneseCalendar())
      Console.WriteLine("The current calendar for the {0} culture is {1}",
                        ci.Name, 
                        CalendarUtilities.ShowCalendarName(ci.DateTimeFormat.Calendar))
      
      CalendarUtilities.ChangeCalendar(ci, New UmAlQuraCalendar())
      Console.WriteLine("The current calendar for the {0} culture is {1}",
                        ci.Name, 
                        CalendarUtilities.ShowCalendarName(ci.DateTimeFormat.Calendar))
   End Sub
End Module

Public Class CalendarUtilities
   Private newCal As Calendar
   Private isGregorian As Boolean
   
   Public Shared Sub ChangeCalendar(ci As CultureInfo, cal As Calendar)
      Dim util As New CalendarUtilities(cal)
      
      ' Is the new calendar already the current calendar?
      If util.CalendarExists(ci.DateTimeFormat.Calendar) Then
         Exit Sub
      End If

      ' Is the new calendar supported?
      If Array.Exists(ci.OptionalCalendars, AddressOf util.CalendarExists) Then
         ci.DateTimeFormat.Calendar = cal
      End If
   End Sub
   
   Private Sub New(cal As Calendar)
      newCal = cal
      
      ' Is the new calendar a Gregorian calendar?
      isGregorian = cal.GetType().Name.Contains("Gregorian")
   End Sub
   
   Private Function CalendarExists(cal As Calendar) As Boolean
      If cal.ToString() = newCal.ToString Then
         If isGregorian Then
            If CType(cal, GregorianCalendar).CalendarType = 
               CType(newCal, GregorianCalendar).CalendarType Then
               Return True
            End If
         Else
            Return True
         End If
      End If
      Return False
   End Function

   Public Shared Function ShowCalendarName(cal As Calendar) As String
      Dim calName As String = cal.ToString().Replace("System.Globalization.", "")
      If TypeOf cal Is GregorianCalendar Then
         calName += ", Type " + CType(cal, GregorianCalendar).CalendarType.ToString()
      End If
      Return calName 
   End Function
End Class
' The example displays the following output:
'    The current calendar for the ar-EG culture is GregorianCalendar, Type Localized
'    The current calendar for the ar-EG culture is GregorianCalendar, Type Localized
'    The current calendar for the ar-EG culture is UmAlQuraCalendar

注釈

Calendarプロパティに関連付けられているカルチャの有効な予定表のみでは、DateTimeFormatInfoオブジェクト。The Calendar property accepts only calendars that are valid for the culture that is associated with the DateTimeFormatInfo object. CultureInfo.OptionalCalendarsプロパティは、特定のカルチャで使用できる暦を指定し、CultureInfo.Calendarプロパティが、カルチャの既定の暦を指定します。The CultureInfo.OptionalCalendars property specifies the calendars that can be used by a particular culture, and the CultureInfo.Calendar property specifies the default calendar for the culture.

重要

和暦の時代 (年号) は天皇の代に基づいているため、変更されることが予想されます。Eras in the Japanese calendars are based on the emperor's reign and are therefore expected to change. たとえば、JapaneseCalendarJapaneseLunisolarCalendar において、2019 年 5 月 1 日から令和時代が始まることになりました。For example, May 1, 2019 marked the beginning of the Reiwa era in the JapaneseCalendar and JapaneseLunisolarCalendar. このような時代 (年号) の変更は、これらのカレンダーを使用するすべてのアプリケーションに影響します。Such a change of era affects all applications that use these calendars. 詳細については「.NET での日本語のカレンダーの新しい時代」をご覧いただき、アプリケーションが影響を受けるかどうかを判断します。See Handling a new era in the Japanese calendar in .NET for more information and to determine whether your applications are affected. 日本語の時代の変更のためのアプリケーションの準備」をご覧いただき、時代の変更に対する状況を確認するために Windows システムでアプリケーションをテストします。See Prepare your application for the Japanese era change for information on testing your applications on Windows systems to ensure their readiness for the era change. 複数の時代 (年号) を含むカレンダーをサポートしている .NET の機能や、複数の時代 (年号) をサポートしているカレンダーを操作する際のベスト プラクティスについては、「Working with eras (時代 (年号) の操作)」をご覧ください。See Working with eras for features in .NET that support calendars with multiple eras and for best practices when working with calendars that support multiple eras.

このプロパティの値を変更する次のプロパティに影響を与えますMonthNamesAbbreviatedMonthNamesDayNamesAbbreviatedDayNamesCalendarWeekRuleFirstDayOfWeekFullDateTimePatternLongDatePatternShortDatePatternYearMonthPattern 。、およびMonthDayPatternします。Changing the value of this property affects the following properties as well: MonthNames, AbbreviatedMonthNames, DayNames, AbbreviatedDayNames, CalendarWeekRule, FirstDayOfWeek, FullDateTimePattern, LongDatePattern, ShortDatePattern, YearMonthPattern, and MonthDayPattern.

たとえば、現在のスレッドのカルチャが日本語の場合は、このプロパティではJapaneseCalendarLocalized GregorianCalendar、またはUSEnglishGregorianCalendarします。For example, if the culture of the current thread is Japanese, this property accepts JapaneseCalendar, LocalizedGregorianCalendar, or USEnglishGregorianCalendar. ときに、JapaneseCalendarが使用される、既定の長い日付の指定子"gg y '\x5e74 AM' \x6708 が '\x65e5'"です。When the JapaneseCalendar is used, the default long date specifier is "gg y'\x5e74'M'\x6708'd'\x65e5'". ときに、 Localized GregorianCalendar、使用する既定の長い日付指定子は"yyyy '\x5e74 AM' \x6708 '\x65e5' が"。When the LocalizedGregorianCalendar, is used, the default long date specifier is "yyyy'\x5e74'M'\x6708'd'\x65e5'".

適用対象

こちらもご覧ください