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