Reputation: 364
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
Upvotes: 0
Views: 672
Reputation: 924
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)
Upvotes: 1