C # An error occurred while saving the time DateTime to the database by week
1) [problem]
It is found that the time I want to save to the database is more than a week in the middle of DateTime, that is, (21:48:54 on Tuesday). mysql reports an error saying that the format time is incorrect.
I use the following method to show that all the time displayed includes a date,
MessageBox. Show (DateTime. Now. (). ToString ());
MessageBox. Show (DateTime. Now. ToLongTimeString (). ToString ());
MessageBox. Show (DateTime. Now. ToLongDateString (). ToString ());
MessageBox. Show (DateTime. Now. tow.datestring (). ToString ());
I use the following method. Although the time popped up does not contain a date, the DateTime type parameter is written in my database. Therefore, the C # code should also store a DateTime type, instead of string type
MessageBox. Show (DateTime. Now (). ToString ("yyyy/MM/dd hh: mm: ss ")); <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KCjxwPrWxztK9q8nPw + ZzdHJpbmfU2bTOx7/records + records = "http://www.bkjia.com/uploads/allimg/160420/0421003G7-0.png" alt = "here write picture description" title = "\">
2) [cause]
Later, I found that my time was previously set to bring the week, so the time will always pop up here.
3) [Problem Solving]
Solution 1:
If you change the time format to the following format, the time does not contain weeks.
The following method can only change the time, but cannot change the format of the system display time.
Solution 2:
The modification above is quite simple, but if the display date is set on the customer's machine, it cannot be changed like this.
The idea of this method is to set the system time format as we wanted at the beginning.
Modify HKEY_CURRENT_USER → Control Panel → International in the registry.
// Modify the current system Date Format public static void Main (string [] args) through the registry {// I found that after modifying the time format in the registry, there is no way to refresh the task bar immediately. You must kill the task bar process and restart it... I wonder if I can refresh the taskbar. We should be able to immediately see the modified effect when we change the time format... RegistryKey rkInternational = Registry. currentUser. openSubKey (@ "Control Panel \ International", true); rkInternational. setValue ("s1_date", "yyyy/MM/dd dddd"); // obtain all programs named explorer (taskbar) Process [] ps = Process. getProcessesByName ("explorer"); foreach (Process p in ps) {// kill it. kill (); // Refresh () is useless... // P. Refresh ();} // then run it again. Process. Start ("assumer.exe"); Console. WriteLine ("succeeded"); Console. ReadKey ();}