Skip to content

Instantly share code, notes, and snippets.

@arcao
Created September 9, 2013 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arcao/6491762 to your computer and use it in GitHub Desktop.
Save arcao/6491762 to your computer and use it in GitHub Desktop.
Parse JSON Date created by .NET, for example: /Date(1378670400000-0500)/
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