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
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
By default, it will be from regional and language settings of your computer.
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.
It uses DateTimeFormatInfo.CurrentInfo which contains the different formats.
If you are using DateTime.TryParse(string s,out DateTime result), the output format depends on your machine's CultureInfo.