public static Date getDate ( JSONObject json , String key , Date defaultValue ) { Date result = defaultValue ; if ( json . containsKey ( key ) ) { try { String secondsString = json . getString ( key ) ; //In gerrit, time is written in seconds, not milliseconds. Long milliseconds = TimeUnit . SECONDS . toMillis ( Long . parseLong ( secondsString ) ) ; result = new Date ( milliseconds ) ; // CS IGNORE EmptyBlockCheck FOR NEXT 2 LINES. REASON: result is already set to defaultValue. } catch ( JSONException ex ) { } catch ( NumberFormatException nfe ) { } } return result ; }
Returns the value of a JSON property as a Date if it exists otherwise returns the defaultValue .