Reputation: 3137
I have this date "2018-05-30T16:19:58.016Z"
coming from my Angular app.
In Spring, the field date
is as follows :
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
private Date date;
The date is well stored, but with this format YYYY-MM-dd
.
Is there anything that I'm missing ?
Upvotes: 1
Views: 1820
Reputation: 6704
MySql date
type can't hold data with timestamp. It has to be datetime
in order to contain date time with timestamp data.
Upvotes: 1
Reputation: 1854
You probably have to specify the date format going out to the storage, as @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
only specifies the date format for parsing the date into the Date object. Even if your Date has all of the seconds and timezone information, the default Date toString()
is still
Formats a date in the date escape format yyyy-mm-dd.
according to the Java 8 docs. So if you are using that, it would most likely drop all that extra information on conversion.
You can look at this Convert java.util.Date to String for information on how to get a Date to a formatted String.
Upvotes: 1