File tree Expand file tree Collapse file tree
main/java/com/alibaba/fastjson/parser
test/java/com/alibaba/json/bvt/serializer Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -475,6 +475,15 @@ public boolean scanISO8601DateIfMatch(boolean strict) {
475475 }
476476 }
477477
478+ } else if (timeZoneFlag == 'Z' ) {// UTC
479+ timzeZoneLength = 1 ;
480+ if (calendar .getTimeZone ().getRawOffset () != 0 ) {
481+ String [] timeZoneIDs = TimeZone .getAvailableIDs (0 );
482+ if (timeZoneIDs .length > 0 ) {
483+ TimeZone timeZone = TimeZone .getTimeZone (timeZoneIDs [0 ]);
484+ calendar .setTimeZone (timeZone );
485+ }
486+ }
478487 }
479488
480489 char end = charAt (bp + (20 + millisLen + timzeZoneLength )) ;
Original file line number Diff line number Diff line change 1+ package com .alibaba .json .bvt .serializer ;
2+
3+ import java .util .Calendar ;
4+
5+ import junit .framework .TestCase ;
6+
7+ import org .junit .Assert ;
8+
9+ import com .alibaba .fastjson .JSON ;
10+
11+ public class DateTest_ISO8601_UTCTime extends TestCase {
12+
13+ public void test_date () throws Exception {
14+ String text = "{\" gmtCreate\" :\" 2014-10-09T03:07:07.000Z\" }" ;
15+
16+ Calendar date = JSON .parseObject (text , VO .class ).getGmtCreate ();
17+ Assert .assertNotNull (date );
18+
19+ Assert .assertEquals (0 , date .getTimeZone ().getRawOffset () / (3600 * 1000 ));
20+ }
21+
22+ public static class VO {
23+
24+ private Calendar gmtCreate ;
25+
26+ public Calendar getGmtCreate () {
27+ return gmtCreate ;
28+ }
29+
30+ public void setGmtCreate (Calendar gmtCreate ) {
31+ this .gmtCreate = gmtCreate ;
32+ }
33+
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments