C#: Display the string representation of a date using the long date format
Write a C# Sharp program to display the string representation of a date using the long date format.
Sample Solution:-
C# Sharp Code:
using System;
public class Exercise25
{
public static void Main()
{
// Create a DateTime object representing August 14, 2009, at 5:23:15 AM.
DateTime august14 = new DateTime(2009, 8, 14, 5, 23, 15);
// Get the long date formats using the current culture for the date 'august14'.
string[] longaugust14Formats = august14.GetDateTimeFormats('D');
// Display all long date formats for the date 'august14'.
foreach (string format in longaugust14Formats) {
Console.WriteLine(format);
}
}
}
Sample Output:
Friday, August 14, 2009 August 14, 2009 Friday, 14 August, 2009 14 August, 2009
Flowchart:
C# Sharp Code Editor:
Improve this sample solution and post your code through Disqus
Previous: Write a C# Sharp program to display the string representation of a date using all possible standard date and time formats in the computer's current culture (en-US.).
Next: Write a C# Sharp program to display the string representations of a date using the short date format specified for the ja-JP culture.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics