2015-05-26 63 views
0

我碰到下面的日期格式JSON ExpiryDate": "/Date(-62135510400000+0000)/"JSON日期格式missunderstanding

我怎樣才能從中提取日期,並在同一格式的新JSON ???

+1

該值代表1月4日1AD你...你確定這就是你想要的價值? –

+1

這是不好的格式! –

+0

@PareshMayani:嗯,這是一個很常見的格式。它不完全*好*,但不幸的是它很常見... –

回答

0
String json = "Date(-62135510400000+0000)"; 
    String timeString = json.substring(json.indexOf("(") + 1, json.indexOf(")")); 
    String[] timeSegments = timeString.split("\\+"); 
    // May have to handle negative timezones 
    int timeZoneOffSet = Integer.valueOf(timeSegments[1]) * 36000; // (("0100"/100) * 3600 * 1000) 
    long millis = Long.valueOf(timeSegments[0]); 
    Date time = new Date(millis + timeZoneOffSet); 
    System.out.println(time); 

對於日期:

SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); 
String dateString = formatter.format(new Date(millis)); 
+0

謝謝,但我怎樣才能將日期轉換爲這種格式? – infoline110593