C # time datetime contains week deposit database error

Source: Internet
Author: User

1) "Problem"
found that I want to save the time in the database in the middle of a week, that is (2015/11/24 Tuesday 21:48:54) This format of time, MySQL error said format time is incorrect.

I use the following method, the time to bounce out with the date,
MessageBox.Show (DateTime.Now. (). ToString ());
MessageBox.Show (DateTime.Now.ToLongTimeString (). ToString ());
MessageBox.Show (DateTime.Now.ToLongDateString (). ToString ());
MessageBox.Show (DateTime.Now.ToShortDateString (). ToString ());

I use the following method, although the bounce time does not carry the date, but my database is written in the DateTime parameter, so the C # code side should also be stored in a datetime type, rather than string type
MessageBox.Show (DateTime.Now (). ToString ("Yyyy/mm/dd hh:mm:ss"));

When I turn the string above to DateTime again, the date is still there.
MessageBox.Show (Convert.todatetime (dt1. Date.tostring ("Yyyy/mm/dd hh:mm:ss")). ToString ()));

2) "Cause"
Later I found that my time I set the day before the time to bring the week, so this side will always pop up time.

3) [Problem solving]
Workaround One:
Change the format of the time here to the following format, the time is not with the week.

The following method can only, change the time, not change the format of the system display time

Workaround Two:
The above kind of modification is very simple, but if the customer's machine set the display date, can not also ask him to modify it.
The idea of this approach is to set the system time format in the first place and set the system time to the format we want.
By modifying the Hkey_current_user→control panel→international in the registry

 //Modify the current system date format through the registry         Public Static void Main(string[] args) {//I found that after modifying the time format in the registry, there is no way to immediately refresh in the taskbar, you must kill the taskbar process and then turn it back on ... I don't know if there is any way to refresh the taskbar. We should usually change the time format when we can see the modified effect immediately ... RegistryKey rkinternational = Registry.CurrentUser.OpenSubKey (@ "Control panel\international",true); Rkinternational.setvalue ("Sshortdate","Yyyy/mm/dd dddd");//Get All Programs called Explorer (taskbar)Process[] PS = Process.getprocessesbyname ("explorer");foreach(Process PinchPS) {//Kill itP.kill ();//refresh () No use ...                 //p.refresh ();}//Then re-run. Process.Start ("Explorer.exe"); Console.WriteLine ("Success");        Console.readkey (); }

C # time datetime contains week deposit database error

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.