關於jackson中時間字符串的轉換

 

"yyyy-MM-dd'T'HH:mm:ss.SSSZ"
 "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
 "EEE, dd MMM yyyy HH:mm:ss zzz"
 "yyyy-MM-dd"

當屍實體中存在Date類型,但是json字符串中是字符串類型

只支持以上幾種格式否則報錯

 

org.codehaus.jackson.map.JsonMappingException: Can not construct instance of java.util.Date from String value '19802-22T12:00:00.000-0800': not a valid representation (error: Can not parse date "19802-22T12:00:00.000-0800": not compatible with any of standard forms ("yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "EEE, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd"))
 at [Source: java.io.StringReader@183f74d; line: 1, column: 15] (through reference chain: com.masque.json.Person["birthday"])
	at org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163)
	at org.codehaus.jackson.map.deser.StdDeserializationContext.weirdStringException(StdDeserializationContext.java:220)
	at org.codehaus.jackson.map.deser.StdDeserializer._parseDate(StdDeserializer.java:511)
	at org.codehaus.jackson.map.deser.DateDeserializer.deserialize(DateDeserializer.java:26)
	at org.codehaus.jackson.map.deser.DateDeserializer.deserialize(DateDeserializer.java:17)
	at org.codehaus.jackson.map.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:230)
	at org.codehaus.jackson.map.deser.SettableBeanProperty$MethodProperty.deserializeAndSet(SettableBeanProperty.java:334)
	at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:495)
	at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:351)
	at org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:2130)
	at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1394)
	at com.masque.json.JacksonTo.main(JacksonTo.java:15)


查了下資料

 

Letter

Date or Time Component

Presentation

Examples

G

Era designator

Text

AD

y

Year

Year

1996;96

M

Month in year

Month

July;Jul;07

w

Week in year

Number

27

W

Week in month

Number

2

D

Day in year

Number

189

d

Day in month

Number

10

F

Day of week in month

Number

2

E

Day in week

Text

Tuesday;Tue

a

Am/pm marker

Text

PM

H

Hour in day (0-23)

Number

0

k

Hour in day (1-24)

Number

24

K

Hour in am/pm (0-11)

Number

0

h

Hour in am/pm (1-12)

Number

12

m

Minute in hour

Number

30

s

Second in minute

Number

55

S

Millisecond

Number

978

z

Time zone

General time zone

Pacific Standard Time;PST;GMT-08:00

Z

Time zone

RFC 822 time zone

-0800

標準時間格式

 

 

Date and Time Pattern

Result

"yyyy.MM.dd G 'at' HH:mm:ss z"

2001.07.04 AD at 12:08:56 PDT

"EEE, MMM d, ''yy"

Wed, Jul 4, '01

"h:mm a"

12:08 PM

"hh 'o''clock' a, zzzz"

12 o'clock PM, Pacific Daylight Time

"K:mm a, z"

0:08 PM, PDT

"yyyyy.MMMMM.dd GGG hh:mm aaa"

02001.July.04 AD 12:08 PM

"EEE, d MMM yyyy HH:mm:ss Z"

Wed, 4 Jul 2001 12:08:56 -0700

"yyMMddHHmmssZ"

010704120856-0700

"yyyy-MM-dd'T'HH:mm:ss.SSSZ"

2001-07-04T12:08:56.235-0700

"yyyy-MM-dd'T'HH:mm:ss.SSSXXX"

2001-07-04T12:08:56.235-07:00

"YYYY-'W'ww-u"

2001-W27-3

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章