I am making an application. The application uses date format such as
\"2012-11-21 15:22:35\"
.
I already know that the format is \"yyyy-MM-dd HH:mm:ss\
I think you would run into problems with date strings where the month value is <= 12 as this means that the format of that string could be "yyyy-MM-dd"
or "yyyy-dd-MM"
There is no way of knowing which one is the correct one unless you put a preference in your parser.
For example:
2012/08/07
- "could this be July or August?"
You could just brute-force it and hope there is a CultureInfo matching the format
var datestring = "2012-10-05 12:00:03";
DateTime time;
var matchingCulture = CultureInfo.GetCultures(CultureTypes.AllCultures).FirstOrDefault(ci => DateTime.TryParse(datestring, ci, DateTimeStyles.None, out time))