我正在使用SimpleDateFormat将字符串更改为日期格式,并在UTC中更改serverTimezone,但日期是提前一天保存的:
String date="2020-05-05";
public static Date getDateByStringDateYYYYMMDD(String date) {
try {
DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
return format.parse(date);
} catch (Exception ex) {
throw new GenricException(ex.getMessage());
}
}网址: jdbc:mysql://localhost:3306/testdb?useUnicode=true&characterEncoding=utf8&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC&createDatabaseIfNotExist=true
mysql中保存日期如2020-05-04
发布于 2020-05-11 17:49:55
使用此代码
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());
}
}https://stackoverflow.com/questions/61726247
复制相似问题