DateTime.ToString () conversion results are based on the current computer display format to convert, can not agree, and some formats we want to convert them to time, will be error, such as:
2017/11/21/Tuesday 10:23:57, if the conversion of this string is datetime, it will fail, so it is necessary to set a default conversion mode for the program, each time when calling DateTime.ToString (), it is converted directly to the format we want, as follows:
DateTime.ToString ("Yyyy-mm-dd HH:mm:ss")
But this method sometimes feel too troublesome, each need to write, there is no way to write, direct conversion, there, the method is as follows:
Thread.currentthread.currentculture=new CultureInfo ("ZH-CN", True)
{
DateTimeFormat = {ShortDatePattern = "yyyy-mm-dd", Fulldatetimepattern = "Yyyy-mm-dd HH:mm:ss", Longtimepattern = "HH:mm: SS "}
};
Just add the sentence when you initialize it.
C # datetime.tostring () converted to a uniform format