Use the ToString() method to convert a DateTime to a string : DateTime Format : Date Time C# Examples


C# Examples » Date Time » DateTime Format »

 

Use the ToString() method to convert a DateTime to a string









    
using  System;

class  MainClass
{
    public  static  void  Main()
    {
        DateTime  myDateTime  =  new  DateTime(2004,  1,  12,  22,  2,  10);
        Console.WriteLine("myDateTime.ToString()  =  "  +  myDateTime.ToString());
        Console.WriteLine("myDateTime.ToString(\"MMMM  dd,  yyyy\")  =  "  +  myDateTime.ToString("MMMM  dd,  yyyy"));
    }
}
    
   
  
   



Output

myDateTime.ToString() = 12/01/2004 10:02:10 PM
myDateTime.ToString("MMMM dd, yyyy") = January 12, 2004


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Date Time
» DateTime Format