当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET DateTime.DaysInMonth方法代码示例

本文整理汇总了VB.NET中System.DateTime.DaysInMonth方法的典型用法代码示例。如果您正苦于以下问题:VB.NET DateTime.DaysInMonth方法的具体用法?VB.NET DateTime.DaysInMonth怎么用?VB.NET DateTime.DaysInMonth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.DateTime的用法示例。


在下文中一共展示了DateTime.DaysInMonth方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。

示例1: Example

Class Example
   Public Shared Sub Main()
      Const July As Integer = 7
      Const Feb As Integer = 2

      Dim daysInJuly As Integer = System.DateTime.DaysInMonth(2001, July)
      Console.WriteLine(daysInJuly)
      
      ' daysInFeb gets 28 because the year 1998 was not a leap year.
      Dim daysInFeb As Integer = System.DateTime.DaysInMonth(1998, Feb)
      Console.WriteLine(daysInFeb)
      ' daysInFebLeap gets 29 because the year 1996 was a leap year.
      Dim daysInFebLeap As Integer = System.DateTime.DaysInMonth(1996, Feb)
      Console.WriteLine(daysInFebLeap)
   End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System,代码行数:16,代码来源:DateTime.DaysInMonth

输出:

31
28
29

示例2: Example

' 导入命名空间
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim years() As Integer = { 2012, 2014 }
      Dim dtfi As DateTimeFormatInfo = DateTimeFormatInfo.CurrentInfo
      Console.WriteLine("Days in the Month for the {0} culture " +
                        "using the {1} calendar", 
                        CultureInfo.CurrentCulture.Name, 
                        dtfi.Calendar.GetType.Name.Replace("Calendar", ""))
      Console.WriteLine()
      Console.WriteLine("{0,-10}{1,-15}{2,4}", "Year", "Month", "Days")
      Console.WriteLine()
      
      For Each [year] As Integer In years
         For ctr As Integer = 0 To dtfi.MonthNames.Length - 1
            If String.IsNullOrEmpty(dtfi.MonthNames(ctr)) Then 
               Continue For
            End If    
            
            Console.WriteLine("{0,-10}{1,-15}{2,4}", [year], 
                              dtfi.MonthNames(ctr), 
                              DateTime.DaysInMonth([year], ctr + 1))
         Next
         Console.WriteLine() 
      Next
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:29,代码来源:DateTime.DaysInMonth

输出:

Days in the Month for the en-US culture using the Gregorian calendar

Year      Month          Days

2012      January          31
2012      February         29
2012      March            31
2012      April            30
2012      May              31
2012      June             30
2012      July             31
2012      August           31
2012      September        30
2012      October          31
2012      November         30
2012      December         31

2014      January          31
2014      February         28
2014      March            31
2014      April            30
2014      May              31
2014      June             30
2014      July             31
2014      August           31
2014      September        30
2014      October          31
2014      November         30
2014      December         31


注:本文中的System.DateTime.DaysInMonth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。