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



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
Updated on: 2020-06-23T07:51:56+05:30

311 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements