I made a simple web service which worked nice with few systems that it was deployed. Now the date from Oracle causes trouble on other system.
Some info:
Our own methods that accesses oracle returns dates as string in format 15.09.2010 13:15:00
(note year in 4 digits)
System working: -DateTime.ToSring() produces 16.09.10 14:15:49 (used in log-file, note year in 2 digits) -TryParse(string s, out DateTime result); returns true with string 15.09.2010 13:15:00 -System.Globalization.CultureInfo.CurrentUICulture.Name has value "en-US" System NOT working: -DateTime.ToSring() produces 9/16/2010 1:25:51 PM (used in log file) -TryParse(string s, out DateTime result); returns false with string 15.09.2010 13:15:00 -System.Globalization.CultureInfo.CurrentUICulture.Name has value "en-US"
So my questions are:
- What is different with these 2 systems?
- What is the best way to make this code universal (i know i can use formatter for DateTime.TryParse and DateTime.ToString() )
Chances are that the date and time formats on the two machines are configured differently (in Control Panel -> Regional and Language Options -> Formats).
If you want to make this code universal then you should specify an explicit format when using
ToString,TryParseand any other methods that convert aDateTimeto/from text; and use UTC. Your safest bet would probably be one of the ISO-8601 formats; for exampleyyyy-MM-ddTHH:mm:ssZ.