Skip to content

Instantly share code, notes, and snippets.

@arcao
Created September 9, 2013 05:19

Revisions

  1. arcao created this gist Sep 9, 2013.
    16 changes: 16 additions & 0 deletions gistfile1.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    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);
    }