SoFunction
Updated on 2025-03-07

Detailed explanation of the use of method

Parameter description
Get the current thread's area information, includingDateTimeFormatDate display format (date separator) andNumberFormatcurrency.
Test example:
1. The situation where no splitter is used in time:
Copy the codeThe code is as follows:

string  temp = "18991230" ;
DateTime dateTemp = (temp, "yyyyMMdd", , );

2. The situation of using splitters in time:
Copy the codeThe code is as follows:

string  temp = "1899-12-30" ;
DateTime dateTemp = (temp, "yyyy-MM-dd", , );
DateTime dateTemp = (temp, "yyyy/MM/dd", , );

All are correct, reasons:
Get the DateTimeFormat property of the CultureInfo of the current thread as the IFormatProvider. Then, in the method, when the / character of the format parameter is encountered, it will compare whether the current character of the input date string is the DateSeperator of the current DateTimeFormatInfo. If it is, it returns true, that is, conversion is allowed, and if it is not, false is returned. In the current thread's area information, the date separator is -, so the conversion is successful.
If there are splitters, it is best to use the following method:
Copy the codeThe code is as follows:

string  temp = "1899-12-30" ;
DateTimeFormatInfo dtfi = new CultureInfo("zh-CN", false).DateTimeFormat;
DateTime dateTemp =  (temp "yyyy-MM-dd", dtfi, ) ;  //Use the current splitter