My code is like this
DateTime dt = new DateTime(); dt= DateTime.ParseExact("14/09/2017", "dd/MM/yyyy", CultureInfo.InvariantCulture); I am expecting dt to have a format of dd/MM/yyyy but the output I am getting is in MM/dd/yyyy format. This is the correct out put I am getting 9/14/2017 12:00:00 AM. Can anyone please point out what I am doing wrong here?
dt.ToString("dd/MM/yyyy",CultureInfo.InvariantCulture);dt.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture);As @TimSchmelter mentioned,Datetimeobject has no format. You decide the format only when displaying it somewhere.DateTimeis stored as a 8 byte binary block, not as a MM/dd/yyyy string. It's only on a call to the object'sToString()method that the current culture's format is applied and the text generated.