absrtact: The project often needs to use a conversion between date and string, such as a background date object returned to the front page in JSON form, want to convert to YYYY-MM-DD HH:mm:ss format string, While the front-end page submits the form, the Date field expects to be automatically populated with the background controller method's Date object.
The project often requires a conversion between a date and a string, such as when a background date object is returned to the front page in JSON form, and wants to be converted to a string in the YYYY-MM-DD HH:mm:ss format. While the front-end page submits the form, the Date field expects to be automatically populated with the background controller method's Date object.
Background date conversion string, add @jsonformat annotations on your Date Type Property Get method (generally not, usually timestamp (date millisecond value) go to JSP, foreground use tag to convert to ' YYYY-MM-DD ' format), as follows:
Java code
- @JsonFormat (pattern="Yyyy-mm-dd HH:mm:ss", timezone="Asia/shanghai")
- Public Date Getcreatetime () {
- return createtime;
- }
The date string in the front-end form is converted to the date in the background (this is not the only way, see the next blog post):
Java code
- /** end of Article release date */
- @DateTimeFormat (pattern="Yyyy-mm-dd")
Springmvc Date vs. string