SpringMVC json automatically converts the date type to long, springmvcjson

Source: Internet
Author: User

SpringMVC json automatically converts the date type to long, springmvcjson

This morning, I encountered a strange problem. I sent a request directly to the background and returned the page information. The displayed time is normal, for example, 15:42:11. 0, but the time displayed in the information obtained through AJAX is actually a timestamp.

First, I checked whether the time type in the collection returned by the background is a timestamp. When the result is hit with a breakpoint, the time displayed in the collection is also normal. After I press f8, check that the JSON file sent back by the browser is actually a timestamp. I don't believe it, so I repeat it several times. It is true that the set is displayed normally, and a timestamp is generated when a response is sent to the front-end, so I added the json annotation (@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")), But I can't use it, because at present this product does not use the ROM framework, that is, there is no entity. After being depressed, I tried to format it myself.

private List<Map<String,Object>> formatDate(List<Map<String,Object>> list){                List<Map<String,Object>> l = new ArrayList<Map<String,Object>>();        for (Map<String, Object> map : list) {            SimpleDateFormat sdf = new SimpleDateFormat("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);        }        return l;    }

^ _ ^, The format is not converted after completion. After careful check, I found that the time, minute, and second in the original set is still 15:42:11 in milliseconds. 0. If JSON is formatted in milliseconds, the time is not automatically converted to the timestamp.

This problem has been solved successfully!

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.