string formatString = "MMddyyyyHHmmss";
string sample = "20100611221912";
DateTime dt = DateTime.ParseExact(sample, formatString, System.Globalization.CultureInfo.InvariantCulture);
the specific exception thrown is:
System.FormatException: The DateTime represented by the string is not supported in calendar System.Globalization.GregorianCalendar.
Your format should be:
string formatString = "yyyyMMddHHmmsss";
(It can also be "yyyyddMMHHmmsss"
, if it is 06-Noveber-2010)
Considering your Date is dt = {11/06/2010 10:19:12 PM}
(11-June-2010)
For your current format:
MMddyyyyHHmmss
20100611221912
MM can't be 20
, since MM
stands for Month. So your code should be:
string formatString = "yyyyMMddHHmmsss";
string sample = "20100611221912";
DateTime dt = DateTime.ParseExact(sample, formatString, System.Globalization.CultureInfo.InvariantCulture);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With