我将日期传递为"scoreTimestamp": "2015-04-15T10:00:00.000Z",
然后将json保存为字符串在数据库中使用方法
ObjectMapper objMapper = new ObjectMapper();
String ratingData = objMapper.writeValueAsString(scoreTimestamp);
我希望日期为:" scoreTimestamp":"2015-04-15 10:00",其中objectMapper将其转换为:
"scoreTimestamp" : {
"year" : 2015,
"dayOfMonth" : 15,
"dayOfWeek" : 3,
"era" : 1,
"dayOfYear" : 105,
"monthOfYear" : 4,
"weekyear" : 2015,
"yearOfEra" : 2015,
"yearOfCentury" : 15,
"weekOfWeekyear" : 16,
"centuryOfEra" : 20,
"millisOfSecond" : 0,
"millisOfDay" : 36000000,
"secondOfMinute" : 0,
"secondOfDay" : 36000,
"minuteOfHour" : 0,
"minuteOfDay" : 600,
"hourOfDay" : 10,
"zone" : {
"fixed" : true,
"id" : "UTC"
},
有人能帮我一下吗? 从Jackson v2.0开始,您可以直接在字段上使用@JsonFormat注释:
@JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", timezone="GMT")
private Date scoreTimestamp;
或者设置为默认值
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm a z");
objMapper.setDateFormat(df);