Home > Back-end > Insert the Java mysql date time is wrong
Insert the Java mysql date time is wrong
Time:11-01
Need to insert time to mysql, including mysql corresponding field properties for the Date, the Java code is as follows:
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); Try { Java. SQL. The Date the register=new Java, SQL, the Date (SDF. Parse (us) getregisterTime ()). The getTime ()); Java. SQL. Date lastlogin=new Java, SQL, the Date (SDF. Parse (us) getLastLogin ()). The getTime ()); System. The out. Println (lastlogin. ToString ()); Psts2. SetDate (5, register); Psts2. SetDate (6, lastlogin); } the catch (ParseException e) { e.printStackTrace(); }
The time to insert is the 2017-06-21 System. The out. Println (lastlogin. ToString ()); The output is correct: the 2017-06-21 But after inserted into the database, become the 2017-06-20 time, less a day, register the corresponding time is less a day Database time_zone is "+ 08:00, CST Not the field into a Datetime There is something wrong with the place?
CodePudding user response:
Their top, online, etc
CodePudding user response:
Continue to wait,,,,
CodePudding user response:
Feeling is time zone, you'd better is to time accurate to hours, see how many hours difference, so convenient and find out the reason,