本文整理汇总了VB.NET中System.Globalization.DateTimeFormatInfo.Calendar属性的典型用法代码示例。如果您正苦于以下问题:VB.NET DateTimeFormatInfo.Calendar属性的具体用法?VB.NET DateTimeFormatInfo.Calendar怎么用?VB.NET DateTimeFormatInfo.Calendar使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Globalization.DateTimeFormatInfo
的用法示例。
在下文中一共展示了DateTimeFormatInfo.Calendar属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Example
' 导入命名空间
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 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