After client downloads a file from our server with our app, the app does a ParseExact
on a date string which comes down from the server in the form: yyyy/mm/dd HH:mm:ss
.
After alot of confusion, I noticed in some logs that the date on the clients system was 19/7/2554
. As is turns out this is a valid time as in Thailand, Windows defaults to the Buddhist era time system, where it is the year 2554.
My parse exact is done with an invariant culture, which I suspect may be the problem, but I thought that the culture referred to the format which you were trying to parse?
The exception message I get is: String was not recognized as a valid DateTime
because the day of week was incorrect
The CultureInfo also contains calendar information. If the TryParseExact method has access to the correct calendar information then it will be able to parse the date correctly.
http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.calendar.aspx
If you replace the InvariantCulture CultureInfo with the Thai CultureInfo then the default calendar for that culture will be used.
Alternatively, you could use an overload of the TryParse method that does not require a CultureInfo. The culture that is used in this case will be dependant on the user's regional settings in Windows.
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