Formatting Problem Date with DateTime

Posted by Florian on Stack Overflow See other posts from Stack Overflow or by Florian
Published on 2011-01-14T06:37:19Z Indexed on 2011/01/14 6:53 UTC
Read the original article Hit count: 357

Filed under:
|
|
|

Hello,

I want to display a date with this format :

  • MM/dd/yyyy HH:mm:ss tt

for example :

  • 01/04/2011 03:34:03 PM

but I have a problem with the following code

class Program
{
    static void Main(string[] args)
    {
        DateTime dt = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 0, 0, 0);
        string displayedDate = dt.ToString("MM/dd/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);
        Console.WriteLine(displayedDate);
        Console.Read();
    }
}

displays :

01/04/2011 12:00:00 AM

instead of

01/04/2011 00:00:00 AM

Anyone knows why ?

Thank you !

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET