C # date formatting,
Generally, the date format of our computer is yyyy-M-d, which is the default format of the system, but sometimes, to display, we may only display the year and month yyyy-M, in this case, the date displayed by the DatePicker control is also yyyy-M,
Therefore, the date obtained through the text attribute of the DatePicker control is only a year and a month, but this is not what we want, we need a day, so no matter how the computer is set, we all need to set the DatePicker control to the format we need.
In this case, the date format is required,
The formatted code is
Thread. currentThread. currentCulture = new CultureInfo ("zh-CN"); Thread. currentThread. currentCulture = (CultureInfo) Thread. currentThread. currentCulture. clone (); Thread. currentThread. currentCulture. dateTimeFormat. shortDatePattern = "yyyy-MM-dd ";
You only need to put the three lines of code in the constructor. If you need different formats, replace yyyy-MM-dd.