Jackson time format, time annotations @JsonFormat usage, jet lag problem description

Source: Internet
Author: User

Http://www.sojson.com/blog/246.html

*******************************************

@JsonFormat use

We can have two usages (I know), on the object property, or on the method of the property, getter as shown in the following code:

Add to attribute:

/** Update Time  the user can click Update to save the latest update time. **/@JsonFormat (Pattern= "Yyyy-mm-dd HH:mm:ss")private Date updatetime;

Add to getter Method:

@JsonFormat (pattern= "Yyyy-mm-dd HH:mm:ss") public Date getupdatetime () {    return  updatetime;}

The output of the above results is the same. This is nothing to explain. Specific output format, self-tuning pattern .

@JsonFormat 8-hour difference.

The above use directly, in our China and our Beijing time, will be 8 hours, because we are East eight (Beijing time).

So we want to specify the time zone () when formatting timezone , the code is as follows:

/** Update Time  the user can click Update to save the latest update time. **/@JsonFormat (Pattern= "Yyyy-mm-dd HH:mm:ss", timezone= "Gmt+8")  Private Date UpdateTime;

That is, add a property, timezone="GMT+8" you can, getter method I will not write, the same.

Let me see the result, I this interface is this output: Public security Network prepared query, to http://www.sojson.com/api/gongan/sina.com.cn for example

    {        "data":{            "id": "11000002000016",            "sitename": "Sina Net",            " SiteDomain ":" sina.com.cn ",            " SiteType ":" Interactive ",            " CDate ":" 2016-01-21 ",            "ComType": "Enterprise",            "comname": "Beijing Sina Internet Information Service Co., Ltd.",            "comaddress": "Beijing network Security Corps" ,             // look at this ... This is just the output.          },        "status":    

Jackson time formatting, time annotations @JsonFormat usage, jet lag problem description

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.