DateTime.ToLongDateString() Method in C#


The DateTime.ToLongDateString() method in C# is used to convert the value of the current DateTime object to its equivalent long date string representation.

Syntax

Following is the syntax −

public string ToLongDateString ();

Example

Let us now see an example to implement the DateTime.ToLongDateString() method −

using System;
public class Demo {
   public static void Main() {
      DateTime d = new DateTime(2019, 10, 11, 9, 10, 45);
      Console.WriteLine("Date = {0}", d);
      string str = d.ToLongDateString();
      Console.WriteLine("Long date string representation = {0}", str);
   }
}

Output

This will produce the following output −

Date = 10/11/2019 9:10:45 AM
Long date string representation = Friday, October 11, 2019

Example

Let us now see another example to implement the DateTime.ToLongDateString() method −

using System;
using System.Globalization;
public class Demo {
   public static void Main() {
      DateTime d = DateTime.Now;
      Console.WriteLine("Date = {0}", d);
      Console.WriteLine("Current culture = "+CultureInfo.CurrentCulture.Name);
      var pattern = CultureInfo.CurrentCulture.DateTimeFormat;
      string str = d.ToLongDateString();
      Console.WriteLine("Long date string = {0}", pattern.LongDatePattern);
      Console.WriteLine("Long date string representation = {0}", str);
   }
}

Output

This will produce the following output −

Date = 10/16/2019 8:39:08 AM
Current culture = en-US
Long date string = dddd, MMMM d, yyyy
Long date string representation = Wednesday, October 16, 2019

Updated on: 05-Nov-2019

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements