BleutradeUtils { public static Date toDate(String timeStamp) { try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss'.'SSS"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); return sdf.parse(timeStamp); } catch (ParseException e) { try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); return sdf.parse(timeStamp); } catch (ParseException e1) { return null; } } }  static String toPairString(CurrencyPair currencyPair); static CurrencyPair toCurrencyPair(String pairString); static Date toDate(String timeStamp);  }
@Test public void shouldConvertStringToDate() { assertThat(BleutradeUtils.toDate("2015-12-14 11:27:16.323").getTime()) .isEqualTo(1450092436323L); assertThat(BleutradeUtils.toDate("2015-12-14 11:15:25").getTime()).isEqualTo(1450091725000L); assertThat(BleutradeUtils.toDate("yyyy-MM-dd")).isNull(); assertThat(BleutradeUtils.toDate("")).isNull(); }