Date object converted to MySQL and String has one second offset
I am using hibernate and spring with AWS 'Aurora
And the data source is 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 between dateTime and string in Aurora which is strange. Can this be solved or explained? Thank.
+3
source to share
No one has answered this question yet
Check out similar questions: