Use the ToLongDateString() and ToShortDateString() methods to convert the date parts of a DateTime to long and short date strings : DateTime Format : Date Time C# Examples


C# Examples » Date Time » DateTime Format »

 

Use the ToLongDateString() and ToShortDateString() methods to convert the date parts of a DateTime to long and short date strings









    
using  System;

class  MainClass
{
    public  static  void  Main()
    {
        DateTime  myDateTime11  =  new  DateTime(2004,  1,  15,  23,  2,  5);
        Console.WriteLine("myDateTime11  =  "  +  myDateTime11);
        Console.WriteLine("myDateTime11.ToLongDateString()  =  "  +  myDateTime11.ToLongDateString());
        Console.WriteLine("myDateTime11.ToShortDateString()  =  "  +  myDateTime11.ToShortDateString());


    }
}
    
   
  
   



Output

myDateTime11 = 15/01/2004 11:02:05 PM
myDateTime11.ToLongDateString() = January 15, 2004
myDateTime11.ToShortDateString() = 15/01/2004


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Date Time
» DateTime Format