I'm using hibernate and spring with AWS' Aurora
And datasource: url: jdbc:mysql://test-cluster.xxxxxxx.us-west-2.rds.amazonaws.com:3306/db_example?useLegacyDatetimeCode=false to convert timezone
@RestController
public class TestDate {
@Autowired
DateEntityRepository dateEntityRepository;
@RequestMapping(value = "/v0/test")
public String test() {
DateEntity dateEntity = new DateEntity();
Date date = new Date();
dateEntity.setCreateTime(date);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
String dateString = simpleDateFormat.format(date);
dateEntity.setDateString(dateString);
dateEntityRepository.save(dateEntity);
return "ok";
}
}
However there seems to be one second difference the dateTime and string in Aurora
which is weird. Can it be resolved or explained? Thanks.