0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Thymeleaf 日付のフォーマット

Posted at

背景

画面のインプットボックスに2025/03/11 18:01を入力して、バックエンドに送信して、再表示はTue Mar 11 18:01:00 JST 2025になっています。

原因

Dateフォーマットが未設定なっています。

public class form {
    @DateTimeFormat (pattern = "yyyy/MM/dd HH:mm")
    private Date startDate;
}

調査経緯

<form th:object:testform>
  <input id="startDate" name="startDate" th:field="*{startDate}"   
    th:value="${#dates.format(start, 'yyyy/MM/dd')}" type="text">
  </input>
</form>

最初はth:fieldとth:valueの関係が分かりません。js側で日付のフォーマットを"yyyy/MM/dd HH:mm"にして、表示するのは問題ないはずと思いました。
このth:valueがここでは余計なものだと思います。

参考:

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?