「C#」指定年月の日数を取得する
書式
DateTime.DaysInMonth(年, 月)
年月を指定してその月の日数を取得する。
使用例
using System;
class Arkgame
{
public static void Main()
{
//2020年10月を指定
int days = DateTime.DaysInMonth(2021, 10);
//2020年9月を指定
int days2 = DateTime.DaysInMonth(2021,11);
Console.WriteLine("2021年10月の日数: "+days.ToString() );
Console.WriteLine("2021年11月の日数: "+days2.ToString() );
Console.ReadKey();
}
}
using System;
class Arkgame
{
public static void Main()
{
//2020年10月を指定
int days = DateTime.DaysInMonth(2021, 10);
//2020年9月を指定
int days2 = DateTime.DaysInMonth(2021,11);
Console.WriteLine("2021年10月の日数: "+days.ToString() );
Console.WriteLine("2021年11月の日数: "+days2.ToString() );
Console.ReadKey();
}
}
using System; class Arkgame { public static void Main() { //2020年10月を指定 int days = DateTime.DaysInMonth(2021, 10); //2020年9月を指定 int days2 = DateTime.DaysInMonth(2021,11); Console.WriteLine("2021年10月の日数: "+days.ToString() ); Console.WriteLine("2021年11月の日数: "+days2.ToString() ); Console.ReadKey(); } }
実行結果
2021年10月の日数: 31
2021年11月の日数: 30