'Spring's @DateTimeFormat ignores wanted date format pattern
Can't get my head on how date formatting using @DateTimeFormat works. I send query with date params being:
dateCreateFrom - 01.04.2022T00%3A00%3A00
dateCreateTo - 30.04.2022T00%3A00%3A00
But at the controller endpoint I get dates like: 2022-04-30T00:00
Controller looks like:
@DateTimeFormat(pattern = "dd.MM.yyyy'T'HH:mm:ss")
dateCreateFrom: LocalDateTime? = null,
@DateTimeFormat(pattern = "dd.MM.yyyy'T'HH:mm:ss")
dateCreateTo: LocalDateTime? = null,
Maybe someone can explain me why I get such results and how can I get results that I want to (dd.MM.yyyy'T'HH:mm:ss)
Any help appreciated
Solution 1:[1]
date if milliseconds and 13 digits(hex to date)
val dtlong = Date(date)
val sdfdate = SimpleDateFormat("dd.MM.yyyy'T'HH:mm:ss", Locale.getDefault()).format(dtlong)
date if milliseconds and 10 digits(hex to date)
val dtlong = Date(date*1000)
val sdfdate = SimpleDateFormat("dd.MM.yyyy'T'HH:mm:ss", Locale.getDefault()).format(dtlong)
string to date
val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH)
val mDate = formatter.parse(dateStr)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ă–mer Seyfettin Yavuzyi?it |
