Spring boot returns the date type. springboot returns the date type.

Source: Internet
Author: User

Spring boot returns the date type. springboot returns the date type.

The database field type is datetime. The object storage type is date.

We read the data from the database and return it to the front-end. We found that the date type is displayed in milliseconds. How to format it? Here are two methods:

Add the following globally in the configuration file:

Spring. jackson. date-format = yyyy-MM-dd HH: mm: ss
Spring. jackson. time-zone = GMT + 8

One is to add a field above it:

@ JsonFormat (timezone = "GMT + 8", pattern = "yyyy-MM-dd HH: mm: ss ")

Add the following in the get method:

@ JsonFormat (pattern = "yyyy-MM-dd HH: mm: ss", timezone = "GMT + 08:00 ")

 

 

Another type: Use Alibaba's fastjson for serialization, and the Controller returns a String. Configure the time type when deserializing the returned value.

Related Article

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.