本文整理匯總了C#中System.DateTime.IsLeapYear方法的典型用法代碼示例。如果您正苦於以下問題:C# DateTime.IsLeapYear方法的具體用法?C# DateTime.IsLeapYear怎麽用?C# DateTime.IsLeapYear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.DateTime
的用法示例。
在下文中一共展示了DateTime.IsLeapYear方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
using System;
public class IsLeapYear
{
public static void Main()
{
for (int year = 1994; year <= 2014; year++)
{
if (DateTime.IsLeapYear(year))
{
Console.WriteLine("{0} is a leap year.", year);
DateTime leapDay = new DateTime(year, 2, 29);
DateTime nextYear = leapDay.AddYears(1);
Console.WriteLine(" One year from {0} is {1}.",
leapDay.ToString("d"),
nextYear.ToString("d"));
}
}
}
}
輸出:
1996 is a leap year. One year from 2/29/1996 is 2/28/1997. 2000 is a leap year. One year from 2/29/2000 is 2/28/2001. 2004 is a leap year. One year from 2/29/2004 is 2/28/2005. 2008 is a leap year. One year from 2/29/2008 is 2/28/2009. 2012 is a leap year. One year from 2/29/2012 is 2/28/2013.
示例2: Main
//引入命名空間
using System;
class MainClass
{
public static void Main()
{
bool boolResult = DateTime.IsLeapYear(2004);
Console.WriteLine("DateTime.IsLeapYear(2004) = " + boolResult);
}
}