Mysql 我正在使用SimpleDataFormat将字符串更改为日期格式,并将服务器时区更改为UTC格式,但日期会提前一天保存
我正在使用SimpleDataFormat将字符串更改为日期格式,并将服务器时区更改为UTC格式,但日期会提前一天保存: 字符串日期=“2020-05-05” url:jdbc:mysql://localhost:3306/testdb?useUnicode=true&characterEncoding=utf8&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC&createDatabaseIfNotExist=true 在mysql中保存的日期类似于2020-05-04Mysql 我正在使用SimpleDataFormat将字符串更改为日期格式,并将服务器时区更改为UTC格式,但日期会提前一天保存,mysql,spring-boot,Mysql,Spring Boot,我正在使用SimpleDataFormat将字符串更改为日期格式,并将服务器时区更改为UTC格式,但日期会提前一天保存: 字符串日期=“2020-05-05” url:jdbc:mysql://localhost:3306/testdb?useUnicode=true&characterEncoding=utf8&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC&createDatabaseIfNotExist=true 在m
public static Date getDateByStringDateYYYYMMDD(String date) {
try {
DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
format.setTimeZone(TimeZone.getTimeZone("GMT"));
return format.parse(date);
} catch (Exception ex) {
throw new GenricException(ex.getMessage());
}
}
你应该知道问题出在哪里,为什么它也起作用
public static Date getDateByStringDateYYYYMMDD(String date) {
try {
DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
format.setTimeZone(TimeZone.getTimeZone("GMT"));
return format.parse(date);
} catch (Exception ex) {
throw new GenricException(ex.getMessage());
}
}