w3resource logo


C# Sharp Programming Exercises

C# Sharp Exercises: Print all possible standard date and time formats

Secondary Nav

C# Sharp DateTime : Exercise-24 with Solution

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.).

Expected Output :

7/28/2009                                                                        
7/28/09                                                                          
07/28/09                                                                         
07/28/2009                                                                       
09/07/28                                                                         
2009-07-28                                                                       
28-Jul-09                                                                        
Tuesday, July 28, 2009                                                           
July 28, 2009  
......      

C# Sharp Code:

using System;
public class Example24
{
  public static void Main(String[] argv){  
    DateTime july28 = new DateTime(2009, 7, 28, 5, 23, 15, 16);

string[] july28Formats = july28.GetDateTimeFormats();

// Print out july28 in all DateTime formats using the default culture.
foreach (string format in july28Formats) {
	Console.WriteLine(format);
}
  }
}

C# Sharp Practice online:

using System;
public class Example24
{
  public static void Main(String[] argv){  
    DateTime july28 = new DateTime(2009, 7, 28, 5, 23, 15, 16);

string[] july28Formats = july28.GetDateTimeFormats();

// Print out july28 in all DateTime formats using the default culture.
foreach (string format in july28Formats) {
	Console.WriteLine(format);
}
  }
}

Improve this sample solution and post your code through Disqus.



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

Python: Fizzbuzz

C++: Decimal to binary conversion

JavaScript: Need Help in JavaScript

Python: Help me with this program