DateTime ToString format

DateTime ToString method formats the result as a short date followed by a long time.


using System;
using System.Text;
class Sample
{
    public static void Main()
    {

        DateTime thisYear = new DateTime(2007, 1, 1);

        Console.WriteLine(thisYear.ToString()); 
    }
}

The output:


1/1/2007 12:00:00 AM

Calling ToString on a DateTimeOffset also shows the offset


using System;
using System.Text;
class Sample
{
    public static void Main()
    {
        DateTimeOffset dt = new DateTimeOffset(2000, 2, 3, 10, 20, 30, new TimeSpan());

        Console.WriteLine(dt.ToString()); 
    }
}

The output:


2/3/2000 10:20:30 AM +00:00
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.