Set Jackson Timezone for Date deserialization

后端 未结 9 610
终归单人心
终归单人心 2020-12-13 04:23

I\'m using Jackson (via Spring MVC Annotations) to deserialize a field into a java.util.Date from JSON. The POST looks like - {\"enrollDate\":\"2011-09-28

9条回答
  •  轮回少年
    2020-12-13 05:07

    Your date object is probably ok, since you sent your date encoded in ISO format with GMT timezone and you are in EST when you print your date.

    Note that Date objects perform timezone translation at the moment they are printed. You can check if your date object is correct with:

    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    cal.setTime(date);
    System.out.println (cal);
    

提交回复
热议问题