tags:

views:

44

answers:

3

I have the following code.

using System;
using System.Globalization;

   class testCompile
    {
        static void Main(string[] args)
        {
            CultureInfo provider = CultureInfo.InvariantCulture;
            string format = "mm/d/yyyy";
            string strInput = "11/5/2010";
            string strOutput = DateTime.ParseExact(strInput, format, provider).ToString();
            Console.WriteLine("string Looks Like : {0}", strOutput);
        }
    }

1) If I try to set the format to "mm/dd/yyyy", the above code throws an error at runtime.

2) I am getting an output of 1/5/2010 12:11:00 AM for the above code.

Where exactly is the 12:00:00 AM coming from?

How did Guy Fawkes Day change to 5th of Jan?

Could someone please explain what is going on?

+4  A: 

mm means minutes; MM means months.

SLaks
+3  A: 

The month should be capital M or MM.

See Custom Date and Time Format Strings for the complete reference.

Lucero
+4  A: 

1) Since you didn't specify a time, it uses the default, 12:00:00 AM.

2) You need to use "MM" to specify the month in your format string, rather than "mm" (minutes). See Custom Date and Time Format Strings for all the details you can handle.

Jeff Sternal
string format = "M/d/yyyy"; is going to work for all situations.
abhi