Chuẩn "Y" (Year Month) hiển thị năm và tháng. Mẫu: yyyy MMMM. Tùy thuộc DateTimeFormatInfo.YearMonthPattern.
Ví dụ minh họa
using System;
using System.Globalization;
class Demo
{
static void Main()
{
DateTime date = new DateTime(2018, 9, 7, 7, 55, 20);
Console.WriteLine(date.ToString("Y", CultureInfo.CreateSpecificCulture("en-US")));
}
}
Kết quả đầu ra
September 2018
Lưu ý: Giữa "Y" (Year Month) và "y" (lowercase) cho cùng kết quả. Không bao gồm ngày, giờ.