I try to parse a date-time stamp from an external system as following:
DateTime expiration;
DateTime.TryParse("2011-04-28T14:00:00", out expiration);
Unfortunately it is not recognized. How can I parse this successfully?
sl3dg3
Specify the exact format you want in DateTime.TryParseExact
:
DateTime expiration;
string text = "2011-04-28T14:00:00";
bool success = DateTime.TryParseExact(text,
"yyyy-MM-ddTHH:mm:ss",
CultureInfo.InvariantCulture,
DateTimeStyles.None,
out expiration);
you can use DateTime.TryParseExact
instead.
How to create a .NET DateTime from ISO 8601 format
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