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


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

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


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

示例1: Example

Module Example
   Public Sub Main()
      Dim baseDate As Date = #2/29/2000#
      Console.WriteLine("    Base Date:        {0:d}", baseDate)
      Console.WriteLine()
      
      ' Show dates of previous fifteen years.
      For ctr As Integer = -1 To -15 Step -1
         Console.WriteLine("{0,3} years ago:        {1:d}", 
                           ctr, baseDate.AddYears(ctr))
      Next
      Console.WriteLine()
      ' Show dates of next fifteen years.
      For ctr As Integer = 1 To 15
         Console.WriteLine("{0,3} years from now:   {1:d}", 
                           ctr, baseDate.AddYears(ctr))
      Next      
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:19,代码来源:DateTime.AddYears

输出:

Base Date:        2/29/2000

1 year(s) ago:        2/28/1999
2 year(s) ago:        2/28/1998
3 year(s) ago:        2/28/1997
4 year(s) ago:        2/29/1996
5 year(s) ago:        2/28/1995
6 year(s) ago:        2/28/1994
7 year(s) ago:        2/28/1993
8 year(s) ago:        2/29/1992
9 year(s) ago:        2/28/1991
10 year(s) ago:        2/28/1990
11 year(s) ago:        2/28/1989
12 year(s) ago:        2/29/1988
13 year(s) ago:        2/28/1987
14 year(s) ago:        2/28/1986
15 year(s) ago:        2/28/1985

1 year(s) from now:   2/28/2001
2 year(s) from now:   2/28/2002
3 year(s) from now:   2/28/2003
4 year(s) from now:   2/29/2004
5 year(s) from now:   2/28/2005
6 year(s) from now:   2/28/2006
7 year(s) from now:   2/28/2007
8 year(s) from now:   2/29/2008
9 year(s) from now:   2/28/2009
10 year(s) from now:   2/28/2010
11 year(s) from now:   2/28/2011
12 year(s) from now:   2/29/2012
13 year(s) from now:   2/28/2013
14 year(s) from now:   2/28/2014
15 year(s) from now:   2/28/2015


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