Created
September 9, 2013 05:19
-
-
Save arcao/6491762 to your computer and use it in GitHub Desktop.
Parse JSON Date created by .NET, for example: /Date(1378670400000-0500)/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected static Date parseJsonDate(String date) { | |
Pattern DATE_PATTERN = Pattern.compile("/Date\\((-?\\d+)([-+]\\d{4})?\\)/"); | |
Matcher m = DATE_PATTERN.matcher(date); | |
if (m.matches()) { | |
long time = Long.parseLong(m.group(1)); | |
long zone = 0; | |
if (m.group(2) != null && m.group(2).length() > 0) | |
zone = Integer.parseInt(m.group(2)) / 100 * 1000 * 60 * 60; | |
return new Date(time + zone); | |
} | |
logger.error("parseJsonDate failed: " + date); | |
return new Date(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment