Encountered a strange problem this morning, directly to the background to send the request to return the page information displayed in the time is normal, such as: 2016-03-17 15:42:11.0, but the information obtained through Ajax to show the time is actually a timestamp.
I first check the background back to the collection of time type is not the time stamp, the results hit the breakpoint found in the collection display time is also normal, I press F8 Skip, check the browser sent back to JSON corresponding incredibly is time stamp, I do not believe, so repeatedly repeated several times, is indeed a set display normal, A response to the front desk is a timestamp, so I Baidu, give the solution is to add JSON annotations on the time get method of the entity ( @JsonFormat
(pattern=
"yyyy-MM-dd HH:mm:ss"
,timezone =
"GMT+8"
)
), but I can not use Ah, because this product is not used in the ROM frame, That is, there is no entity this said Ah, depressed after then I think of a way to format it, to see how not.
PrivateList<map<string,object>> FormatDate (list<map<string,object>>list) {List<Map<String,Object>> L =NewArraylist<map<string,object>>(); for(Map<string, object>map:list) {SimpleDateFormat SDF=NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); if(Map.get ("Add_time")! =NULL) {String add_time= Map.get ("Add_time"). toString (); Try{Date Date=Sdf.parse (add_time); Map.put ("Add_time", Sdf.format (date)); } Catch(ParseException e) {e.printstacktrace (); }} l.add (map); } returnl; }
^_^, after the format is really not converted, I carefully check before I found that the original collection time and seconds after the millisecond 15:42:11.0, the milliseconds to format the JSON will not automatically convert time to timestamp.
To solve this problem successfully!
SPRINGMVC JSON automatically converts the date type to long