DateTimeFormatInfo.Calendar Eigenschaft
Definition
Ruft den für die aktuelle Kultur zu verwendenden Kalender ab oder legen diesen fest.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
Eigenschaftswert
Der für die aktuelle Kultur zu verwendende Kalender.The calendar to use for the current culture. Der Standardwert für InvariantInfo ist ein GregorianCalendar-Objekt.The default for InvariantInfo is a GregorianCalendar object.
Ausnahmen
Die Eigenschaft wird auf null
festgelegt.The property is being set to null
.
Die Eigenschaft wird auf ein Calendar-Objekt festgelegt, das für die aktuelle Kultur ungültig ist.The property is being set to a Calendar object that is not valid for the current culture.
Die Eigenschaft wird festgelegt, und das DateTimeFormatInfo-Objekt ist schreibgeschützt.The property is being set and the DateTimeFormatInfo object is read-only.
Beispiele
Im folgenden Beispiel wird eine ChangeCalendar
Methode definiert, die den aktuellen Kalender einer Kultur in einen angegebenen Kalender ändert, es sei denn, es handelt sich um den aktuellen Kalender, oder wenn Sie nicht von der Kultur unterstützt wird.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. Der Code, der die-Methode aufruft, instanziiert ein CultureInfo -Objekt, das die Kultur Arabisch (Ägypten) darstellt, und versucht zunächst, seinen Kalender in den japanischen Kalender zu ändern.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. Da der japanische Kalender nicht unterstützt wird, führt die-Methode nicht zum Ändern des Kalenders der Kultur.Because the Japanese calendar is not supported, the method makes not change the culture's calendar. Da der um Al-Qura-Kalender jedoch ein Member der-Auflistung ist CultureInfo.OptionalCalendars , ist die-Methode erfolgreich, dass Sie den aktuellen Kalender für die AR-z-Kultur verwendet.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
Hinweise
Die- Calendar Eigenschaft akzeptiert nur Kalender, die für die Kultur gültig sind, die dem-Objekt zugeordnet ist DateTimeFormatInfo .The Calendar property accepts only calendars that are valid for the culture that is associated with the DateTimeFormatInfo object. Die CultureInfo.OptionalCalendars -Eigenschaft gibt die Kalender an, die von einer bestimmten Kultur verwendet werden können, und die- CultureInfo.Calendar Eigenschaft gibt den Standardkalender für die Kultur an.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.
Wichtig
Die Zeitrechnung in japanischen Kalendern basiert auf den Regierungsperioden der Kaiser und wird sich daher erwartungsgemäß ändern.Eras in the Japanese calendars are based on the emperor's reign and are therefore expected to change. Beispiel: Der 1. Mai 2019 markiert den Beginn des Reiwa-Zeitabschnitts in den Kalendern des Typs JapaneseCalendar und JapaneseLunisolarCalendar.For example, May 1, 2019 marked the beginning of the Reiwa era in the JapaneseCalendar and JapaneseLunisolarCalendar. Eine derartige Änderung der Zeitabschnitte betrifft alle Anwendungen, die diese Kalender verwenden.Such a change of era affects all applications that use these calendars. Unter Handling a new era in the Japanese calendar in .NET (Umgang mit einem neuen Zeitabschnitt im japanischen Kalender in .NET) finden Sie weiter Informationen und wie Sie bestimmen können, ob Ihre Anwendungen ebenfalls betroffen sind.See Handling a new era in the Japanese calendar in .NET for more information and to determine whether your applications are affected. Unter Prepare your application for the Japanese era change (Vorbereiten Ihrer Anwendung für die Änderung des Zeitabschnitts im japanischen Kalender) finden Sie Informationen zum Testen Ihrer Anwendungen auf Windows-Systemen, um deren Bereitschaft für die Änderung im Zeitabschnitt sicherzustellen.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. Unter Arbeiten mit Zeiträumen finden Sie Informationen zu Funktionen in .NET, die Kalender mit mehreren Zeitabschnitten unterstützen, sowie bewährte Vorgehensweisen bei der Arbeit mit solchen Kalendern.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.
Wenn Sie den Wert dieser Eigenschaft ändern, wirkt sich dies auch auf die folgenden Eigenschaften aus: MonthNames , AbbreviatedMonthNames , DayNames , AbbreviatedDayNames , CalendarWeekRule , FirstDayOfWeek , FullDateTimePattern , LongDatePattern , ShortDatePattern , YearMonthPattern und 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.
Wenn z. b. die Kultur des aktuellen Threads Japanisch ist, akzeptiert diese Eigenschaft JapaneseCalendar , Localized GregorianCalendar oder USEnglish GregorianCalendar .For example, if the culture of the current thread is Japanese, this property accepts JapaneseCalendar, LocalizedGregorianCalendar, or USEnglishGregorianCalendar. Wenn JapaneseCalendar verwendet wird, ist der standardmäßige Long Date-Spezifizierer "GG y" \x5e74 'm ' \x6708 'd ' \x65e5 ' ".When the JapaneseCalendar is used, the default long date specifier is "gg y'\x5e74'M'\x6708'd'\x65e5'". Wenn Localized GregorianCalendar verwendet wird, ist der standardmäßige Long Date-Spezifizierer "yyyy" \x5e74 'm ' \x6708 d ' \x65e5 ' ".When the LocalizedGregorianCalendar, is used, the default long date specifier is "yyyy'\x5e74'M'\x6708'd'\x65e5'".