DateTimeFormatInfo.Calendar 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
현재 문화권에 사용할 달력을 가져오거나 설정합니다.
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
속성 값
현재 문화권에 사용할 달력입니다. InvariantInfo의 기본값은 GregorianCalendar 개체입니다.
예외
속성이 null
로 설정되어 있습니다.
속성이 현재 문화권에 유효하지 않은 Calendar 개체로 설정되는 경우
속성이 설정되어 있으며 DateTimeFormatInfo 개체가 읽기 전용입니다.
예제
다음 예제에서는 ChangeCalendar
문화권의 현재 달력이 이미 현재 달력이거나 문화권에서 지원되지 않는 경우를 아니면 지정된 달력으로 변경하는 메서드를 정의합니다. 메서드를 호출하는 코드는 CultureInfo 아랍어(아랍어) 문화권 을 나타내는 개체를 인스턴스화하고 먼저 달력을 일본식 달력으로 변경하려고 합니다. 일본식 달력은 지원되지 않으므로 메서드는 문화권의 달력을 변경하지 않습니다. 그러나 um al-Qura 달력은 컬렉션의 멤버이므로 CultureInfo.OptionalCalendars 메서드는 ar-EG 문화권의 현재 달력으로 만드는 데 성공합니다.
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 개체입니다. CultureInfo.OptionalCalendars속성은 특정 문화권에서 사용할 수 있는 달력을 지정하고 CultureInfo.Calendar 속성은 문화권의 기본 달력을 지정합니다.
중요
일본어 달력의 시대는 천황 통치 기간을 기준으로 하므로 변경되어야 합니다. 예를 들어 2019년 5월 1일은 JapaneseCalendar 및 JapaneseLunisolarCalendar에서 레이와 시대의 시작을 나타냅니다. 이러한 시대 변경 내용은 해당 달력을 사용하는 모든 애플리케이션에 영향을 줍니다. 자세한 내용 및 애플리케이션이 영향을 받는지 여부를 확인하려면 .NET에서 일본 달력의 새 시대 처리를참조하세요. Windows 시스템에서 애플리케이션을 테스트하여 시대 변화에 대한 준비 상태를 확인하는 자세한 내용은 일본 연호 변경을 위한 애플리케이션 준비를 참조하세요. 여러 시대가 있는 달력을 지원하는 .NET의 기능 및 여러 연호를 지원하는 달력으로 작업하는 경우 모범 사례는 연호 작업을 참조하세요.
이 속성의 값을 변경하면 , , 및 속성에도 영향을 MonthNames AbbreviatedMonthNames DayNames AbbreviatedDayNames CalendarWeekRule FirstDayOfWeek FullDateTimePattern LongDatePattern ShortDatePattern YearMonthPattern MonthDayPattern 미칩니다.
예를 들어 현재 스레드의 문화권이 일본어인 경우 이 속성은 JapaneseCalendar , 또는 를 Localized GregorianCalendar USEnglish GregorianCalendar 허용합니다. 를 사용하는 경우 JapaneseCalendar 기본 긴 날짜 지정자는 "gg y'\x5e74'M'\x6708'd'\x65e5'"입니다. 를 Localized GregorianCalendar 사용하는 경우 기본 긴 날짜 지정자는 "yyyy'\x5e74'M'\x6708'd'\x65e5'"입니다.