#author("2019-11-26T00:27:43+09:00","","") #navi(../) * うるう年を調べる方法・DaysInMonth [#j192048b] C#,VB(Visual Basic)で指定した年、月で閏年かどうかを調べる方法を紹介します。 サンプルコード(コンソールアプリケーション)もありますのでご活用ください。 今回使用するメソッドは、DateTime.DaysInMonthになります。 #htmlinsert(windev-top.html) #contents * 参考サイト [#j4d2ce41] -[[Microsoft|.NET : DateTime.DaysInMonth(Int32, Int32) メソッド>https://docs.microsoft.com/ja-jp/dotnet/api/system.datetime.daysinmonth?view=netframework-4.8]] * 関連記事 [#k6805956] -[[月末の日を取得する方法・DaysInMonth>.NET/月末の日を取得する方法・DaysInMonth]] * DaysInMonthメソッドについて [#h584e98c] ''DaysInMonth''は引数に指定した年、月の日数を返却します。~ つまり、日数=月末日となるので、月末日を求めることができます。~ もちろん、うるう年も問題なく29日と返却されます。 * サンプルコード [#a88989d9] C#, Visual Basicで閏年を判定するサンプルコードを以下に記します。 ** C# サンプルコード [#l12b233d] C#でDaysInMonthメソッドを利用したサンプルコードになります。 #ref(Program.cs) using System; namespace LeapCS { class Program { static void Main(string[] args) { Console.WriteLine("2019年2月の最終日 : " + DateTime.DaysInMonth(2019,2)); Console.WriteLine("2020年2月の最終日 : " + DateTime.DaysInMonth(2020, 2)); Console.WriteLine("2021年2月の最終日 : " + DateTime.DaysInMonth(2021, 2)); } } } ** Visual Basic サンプルコード [#m7162d1f]