tags:

views:

99

answers:

4

Hello All:

I am converting a string to datetime using DateTime.TryParse in C#. Can somebody tell me, how to know which format C# compiler used to convert the string to valid DateTime. I want to know the datetime format used.

Thanks, Ashwani

A: 

By default, it will be from regional and language settings of your computer.

danish
A: 

You could probably infer it in some cases from CultureInfo.CurrentCulture. But I don't think it's possible to be certain which one it was since multiple formats might be valid in one culture.

If you want to be sure, try using TryParseExact instead.

ho1
+1  A: 

It uses DateTimeFormatInfo.CurrentInfo which contains the different formats.

Darin Dimitrov
A: 

If you are using DateTime.TryParse(string s,out DateTime result), the output format depends on your machine's CultureInfo.

Danny Chen