I am converting a string to datetime using DateTime.TryParse in C#. Can somebody t开发者_如何学编程ell 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
It uses DateTimeFormatInfo.CurrentInfo which contains the different formats.
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.
If you are using DateTime.TryParse(string s,out DateTime result), the output format depends on your machine's CultureInfo.
精彩评论