DateTime.ParseExact returns the current date

I tried the following code:

DateTime dateTime = DateTime.ParseExact("01/02/2013",  //string date
                                        "01/02/2013",  // string format
                                         CultureInfo.InvariantCulture);

I know the format is incorrect. But why, instead of throwing an exception, the current date is returned dateTime = {24/09/2014 12:00:00 AM}.

I know that there should be a valid format for my date MM/dd/yyyy, but why didn’t he throw an exception. I also tried it with DateTime.TryParseExact, it returns the current date instead default(DateTime). It actually came to reading this question .

My question is, how does this parsing work?

+4
source share
3 answers

By MSDN :

, DateTime (00:00:00). , DateTime DateTime.Now.Date.

- " " . , , 02/02/2013 - FormatException

+6

/. , () () .

, , , ( "11/..." "01/..." )

   DateTime.ParseExact("11/02/2013",  
                  "01/02/2013",  // string format
                   CultureInfo.InvariantCulture);

, "MM/yyyy" - , /, .

- DateTime.ParseExact:

, DateTime DateTime.Now.Date.

+5

MSDN:

public static DateTime ParseExact(string s, string format, IFormatProvider provider)

, DateTime DateTime.Now.Date.

+1

All Articles