Sử dụng DaysInMonth để hiển thị số ngày trong tháng.
Thêm năm và tháng làm tham số cho phương thức DaysInMonth () -
DateTime.DaysInMonth(2018, 8);
Sau đây là một ví dụ -
Ví dụ
using System;
using System.Collections.Generic;
using System.Linq;
public class Demo {
public static void Main() {
Console.WriteLine("Today = {0}", DateTime.Today);
int num_days = DateTime.DaysInMonth(2018, 8);
Console.WriteLine("Days in August: "+num_days);
}
} Đầu ra
Today = 9/4/2018 12:00:00 AM Days in August: 31