Reputation: 3136
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?
Upvotes: 1
Views: 144
Reputation: 48623
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.
Upvotes: 4
Reputation: 60236
The month should be capital M
or MM
.
See Custom Date and Time Format Strings for the complete reference.
Upvotes: 3