本文整理汇总了VB.NET中System.Globalization.Calendar类的典型用法代码示例。如果您正苦于以下问题:VB.NET Calendar类的具体用法?VB.NET Calendar怎么用?VB.NET Calendar使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Calendar类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: Main
' 导入命名空间
Imports System.Globalization
Public Class SamplesCalendar
Public Shared Sub Main()
' Sets a DateTime to April 3, 2002 of the Gregorian calendar.
Dim myDT As New DateTime(2002, 4, 3, New GregorianCalendar())
' Uses the default calendar of the InvariantCulture.
Dim myCal As Calendar = CultureInfo.InvariantCulture.Calendar
' Displays the values of the DateTime.
Console.WriteLine("April 3, 2002 of the Gregorian calendar:")
DisplayValues(myCal, myDT)
' Adds 5 to every component of the DateTime.
myDT = myCal.AddYears(myDT, 5)
myDT = myCal.AddMonths(myDT, 5)
myDT = myCal.AddWeeks(myDT, 5)
myDT = myCal.AddDays(myDT, 5)
myDT = myCal.AddHours(myDT, 5)
myDT = myCal.AddMinutes(myDT, 5)
myDT = myCal.AddSeconds(myDT, 5)
myDT = myCal.AddMilliseconds(myDT, 5)
' Displays the values of the DateTime.
Console.WriteLine("After adding 5 to each component of the DateTime:")
DisplayValues(myCal, myDT)
End Sub
Public Shared Sub DisplayValues(myCal As Calendar, myDT As DateTime)
Console.WriteLine(" Era: {0}", myCal.GetEra(myDT))
Console.WriteLine(" Year: {0}", myCal.GetYear(myDT))
Console.WriteLine(" Month: {0}", myCal.GetMonth(myDT))
Console.WriteLine(" DayOfYear: {0}", myCal.GetDayOfYear(myDT))
Console.WriteLine(" DayOfMonth: {0}", myCal.GetDayOfMonth(myDT))
Console.WriteLine(" DayOfWeek: {0}", myCal.GetDayOfWeek(myDT))
Console.WriteLine(" Hour: {0}", myCal.GetHour(myDT))
Console.WriteLine(" Minute: {0}", myCal.GetMinute(myDT))
Console.WriteLine(" Second: {0}", myCal.GetSecond(myDT))
Console.WriteLine(" Milliseconds: {0}", myCal.GetMilliseconds(myDT))
Console.WriteLine()
End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System.Globalization,代码行数:49,代码来源:Calendar 输出:
April 3, 2002 of the Gregorian calendar:
Era: 1
Year: 2002
Month: 4
DayOfYear: 93
DayOfMonth: 3
DayOfWeek: Wednesday
Hour: 0
Minute: 0
Second: 0
Milliseconds: 0
After adding 5 to each component of the DateTime:
Era: 1
Year: 2007
Month: 10
DayOfYear: 286
DayOfMonth: 13
DayOfWeek: Saturday
Hour: 5
Minute: 5
Second: 5
Milliseconds: 5
注:本文中的System.Globalization.Calendar类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论