Year Month ("Y") Format Specifier in C#

CsharpProgrammingServer Side Programming

The Year Month format specifier represents a custom date and time format string.

It is defined by the DateTimeFormatInfo.YearMonthPattern property.

Here is the custom format string.

yyyy MMMM

Example

 Live Demo

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")));
   }
}

Output

September 2018
raja
Published on 12-Sep-2018 16:22:26
Advertisements