DateParamConverter implements ParamConverter<Date> { @Override public Date fromString(String string) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat( _getPattern(string)); try { return simpleDateFormat.parse(string); } catch (ParseException parseException) { throw new WebApplicationException(parseException); } }  @Override Date fromString(String string); @Override String toString(Date date);  }
@Test public void testFromString() { String dateString = "2019-02-18"; Date date = _dateParamConverter.fromString(dateString); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); Assert.assertEquals(18, calendar.get(Calendar.DATE)); Assert.assertEquals(1, calendar.get(Calendar.MONTH)); Assert.assertEquals(2019, calendar.get(Calendar.YEAR)); String dateTimeString = "2019-01-27T08:56:45.236Z"; date = _dateParamConverter.fromString(dateTimeString); calendar = Calendar.getInstance(); calendar.setTime(date); Assert.assertEquals(27, calendar.get(Calendar.DATE)); Assert.assertEquals(8, calendar.get(Calendar.HOUR)); Assert.assertEquals(56, calendar.get(Calendar.MINUTE)); Assert.assertEquals(0, calendar.get(Calendar.MONTH)); Assert.assertEquals(45, calendar.get(Calendar.SECOND)); Assert.assertEquals(2019, calendar.get(Calendar.YEAR)); }