エンティティクラスの日時形式

1. 1つ目のタイプ

 @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

データベースに挿入するための直接アクセス、アクセス方法:

(now()::timestamp を選択)
String todayDate = DateUtil.format(new Date(),"yyyy-MM-dd");

2. 2 番目のタイプ

 @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

時刻を取得するメソッド:

Date date = new Date();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String createTime = simpleDateFormat.format(date);
            Timestamp timestamp = Timestamp.valueOf(createTime);
            topicInfo.setCreateTime(timestamp);

おすすめ

転載: blog.csdn.net/minusn/article/details/131413730