Possible Duplicate:
Parsing a complicated string as DateTime
I have a string date with time that I'd like to parse into a DateTime. I'm not quite sure how to tackle it because of the odd format. Help is appreciated.
Example: Mon Mar 24 13-42-30 2008
DateTime.ParseExact should do what you want:
var dateTime = DateTime.ParseExact(
"Mon Mar 24 13-42-30 2008",
"ddd MMM dd HH-mm-ss yyyy",
CultureInfo.CurrentCulture);
Can someone tell me the difference between using CultureInfo.CurrentCulture and CultureInfo.InvariantCulture, like the other answers? I was assuming things like the day name and month name might need to be parsed in their native language. Thanks.
Try:
var theDate = DateTime.ParseExact(
"Fri Jul 13 13-42-30 2012",
"ddd MMM dd HH-mm-ss yyyy",
System.Globalization.CultureInfo.InvariantCulture);
Date string formatting options can be found here.
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