C # An error occurred while saving the time DateTime to the database by week

Source: Internet
Author: User

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 ();}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.