Given the following 2 lines, pay attention to ".185" and ", 185"
2011-09-15 17:05:37,1852011-09-15 17:05:37.185
Reading from a file (not in my control), and I see that they have dates in both formats. I need to create a function that serves both scenarios.
Is " . " And " , " culture specific?
Any suggestion for such a feature?
This below does not work as I am not getting the date.
class Program { static void Main(string[] args) { string date1="2011-09-15 17:05:37.185"; string date2="2011-09-15 17:05:37,185"; const string format1 = "dd/MM/yyyy HH:mm:ss.ff"; const string format2 = "dd/MM/yyyy HH:mm:ss,ff"; DateTime resultDate1; DateTime resultDate2; DateTime.TryParseExact(date1, format1, CultureInfo.InvariantCulture, DateTimeStyles.None, out resultDate1); DateTime.TryParseExact(date2, format2, CultureInfo.InvariantCulture, DateTimeStyles.None, out resultDate2); Console.WriteLine(resultDate1.ToString()); Console.WriteLine(resultDate2.ToString()); Console.Read(); } }
source share