Springmvc Date vs. string

Source: Internet
Author: User

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
  1. @JsonFormat (pattern="Yyyy-mm-dd HH:mm:ss", timezone="Asia/shanghai")
  2. Public Date Getcreatetime () {
  3. return createtime;
  4. }

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
    1. /** end of Article release date */
    2. @DateTimeFormat (pattern="Yyyy-mm-dd")

Springmvc Date vs. string

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.