In our production environment of 12 servers we have an issue with the code
var date = DateTime.Parse("Thu, 10 Mar 2011 13:15:33 GMT");
and this is not all the time and just on few of the servers (once per month maybe) it will throw the
System.FormatException: String was not recognized as a valid DateTime.
at System.DateTimeParse.Parse(String, DateTimeFormatInfo, DateTimeStyles)
The date “Thu, 10 Mar 2011 13:15:33 GMT” is a real example for today it originates from another environment and is created in the following way
string.Format("{0:R}", ExpiresOn.ToUniversalTime())
The second day we plug servers back in the farm and they will continue to work fine.
- There is any way to avoid this ?
- Because this information is opaque for the consumers we think switching to ticks is this better ?
- Any good practices ?
Thanks
Always use the
CultureInfo.InvariantCulture. This is a rule. Use it for parsing of Dates, of numbers (especially floats/doubles/decimals), for ToString(ing) Dates, numbers (especially floats/doubles/decimals) etc. And if you handle date, always think if it would be better to handle them in UTC or in your local timezone. If you have to handle coordination between servers/persons in multiple timezones, always use (store) UTC dates.