I have some date returned from FTP server like this
Aug 28 11:03
Aug 28 18:06
Sep 6 16:03
Im using this code to parse the time
CultureInfo provider = new CultureInfo("en-US");
_fileDateTime = DateTime.ParseExact(timestring, "MMM dd H:mm", provider);
The first two date work, but the last won’t. Does any one have better ideas in parsing these kind of date format?
MMM d H:mm will work with Sep 6 16:03 but in my case its Sep 6 16:03 will not work, note the double space between Sep and 6
There are multiple issues, one is which is already pointed out in other answers i.e. using single
dfor date since last date is6not06. The other problem with the last date is that it has multiple spaces in between date and month because of that your format which is taking care of dates with single space is not working. You need to first remove the extra space and then parse using format with singled. Try the following code: