Short Date ("d") Format Specifier


The "d" format specifier represents a custom date and time format string.

The format string is defined by culture's DateTimeFormatInfo.ShortDatePattern property.

The custom format string is −

MM/dd/yyyy

Example

 Live Demo

using System;
using System.Globalization;
class Demo {
   static void Main() {
      DateTime myDate = new DateTime(2018,9, 09);
      Console.WriteLine(myDate.ToString("d", DateTimeFormatInfo.InvariantInfo));
      Console.WriteLine(myDate.ToString("d", CultureInfo.CreateSpecificCulture("en-US")));
   }
}

Output

09/09/2018
9/9/2018

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 23-Jun-2020

194 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements