为什么localdatetime的时间部分在使用jpa将其持久化到数据库后会改变它的值?

gpnt7bae  于 2021-07-23  发布在  Java
关注(0)|答案(0)|浏览(189)
//createdAt and lastUpdatedAt are initialised like this:

    LocalDateTime createdAt = LocalDateTime.now(ZoneId.of("UTC"));
    LocalDateTime lastUpdatedAt = LocalDateTime.now(ZoneId.of("UTC"));

    //Rest of the code...

    System.out.println(rocReviewComment.getCreatedAt().toString() + ">>>" + rocReviewComment.getLastUpdatedAt().toString());
    // Initialize the database
    rocReviewCommentRepository.saveAndFlush(rocReviewComment);
    System.out.println(rocReviewComment.getCreatedAt().toString() + ">>>" + rocReviewComment.getLastUpdatedAt().toString());

第一次打印:2021-02-22t16:16:14.755>>>2021-02-22t16:16:14.762
第二次打印:2021-02-22t10:46:44.389>>>2021-02-22t10:46:44.389
你可以看到时间部分被改变了。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题