Sunday, 9 April 2017

C# Program to Display the Date in Various Formats

  1. /*
  2.  * C# Program to Display the Date in Various Formats 
  3.  */
  4. using System;
  5. namespace DateAndTime
  6. {
  7.     class Program
  8.     {
  9.         static int Main()
  10.         {
  11.             DateTime date = new DateTime(2013,6, 23);
  12.             Console.WriteLine("Some Date Formats : ");
  13.             Console.WriteLine("Date and Time:  {0}", date);
  14.             Console.WriteLine(date.ToString("yyyy-MM-dd"));
  15.             Console.WriteLine(date.ToString("dd-MMM-yy"));
  16.             Console.WriteLine(date.ToString("M/d/yyyy"));
  17.             Console.WriteLine(date.ToString("M/d/yy"));
  18.             Console.WriteLine(date.ToString("MM/dd/yyyy"));
  19.             Console.WriteLine(date.ToString("MM/dd/yy"));
  20.             Console.WriteLine(date.ToString("yy/MM/dd"));
  21.             Console.Read();
  22.             return 0;
  23.         }
  24.     }
  25. }
Here is the output of the C# Program:
Some Date Formats :
Date and Time : 6/23/2013 12:00:00 AM
2013-06-23
23-Jun-13
6/23/2013
6/23/13
06/23/2013
06/23/13
13/06/23

No comments:

Post a Comment