Date object converted in MySQL and String has one second offset

Viewed 300

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 MySQL database which is weird. Can it be resolved or explained? Thanks.

0 Answers
Related