@Test public void testParseUTCDateTime() throws Exception { String date = "2016-12-31T12:13:14Z"; ZonedDateTime dateTime = FormatUtils.parseUTCTime(date); int year = dateTime.getYear(); int dayOfMonth = dateTime.getDayOfMonth(); int hour = dateTime.getHour(); assertThat(year, equalTo(2016)); assertThat(dayOfMonth, equalTo(31)); assertThat(hour, equalTo(12)); }
public static ZonedDateTime parseUTCTime(String value) { try { Instant instant = Instant.ofEpochMilli(Long.parseLong(value)); return instant.atZone(ZoneOffset.UTC); } catch (NumberFormatException e) { return Optional.of(ZonedDateTime.parse(value)) .map(zdt -> zdt.withZoneSameInstant(ZoneOffset.UTC)) .get(); } }
FormatUtils { public static ZonedDateTime parseUTCTime(String value) { try { Instant instant = Instant.ofEpochMilli(Long.parseLong(value)); return instant.atZone(ZoneOffset.UTC); } catch (NumberFormatException e) { return Optional.of(ZonedDateTime.parse(value)) .map(zdt -> zdt.withZoneSameInstant(ZoneOffset.UTC)) .get(); } } }
FormatUtils { public static ZonedDateTime parseUTCTime(String value) { try { Instant instant = Instant.ofEpochMilli(Long.parseLong(value)); return instant.atZone(ZoneOffset.UTC); } catch (NumberFormatException e) { return Optional.of(ZonedDateTime.parse(value)) .map(zdt -> zdt.withZoneSameInstant(ZoneOffset.UTC)) .get(); } } private  FormatUtils(); }
FormatUtils { public static ZonedDateTime parseUTCTime(String value) { try { Instant instant = Instant.ofEpochMilli(Long.parseLong(value)); return instant.atZone(ZoneOffset.UTC); } catch (NumberFormatException e) { return Optional.of(ZonedDateTime.parse(value)) .map(zdt -> zdt.withZoneSameInstant(ZoneOffset.UTC)) .get(); } } private  FormatUtils(); static ZonedDateTime parseUTCTime(String value); static Number parseNumber(String value); static String formatNumber(Number value); static String formatNumberFiveCharLimit(Number value); static String formatMillisOrSeconds(Number value); static String generateDefaultValueMessage(String metric, Number value); }
FormatUtils { public static ZonedDateTime parseUTCTime(String value) { try { Instant instant = Instant.ofEpochMilli(Long.parseLong(value)); return instant.atZone(ZoneOffset.UTC); } catch (NumberFormatException e) { return Optional.of(ZonedDateTime.parse(value)) .map(zdt -> zdt.withZoneSameInstant(ZoneOffset.UTC)) .get(); } } private  FormatUtils(); static ZonedDateTime parseUTCTime(String value); static Number parseNumber(String value); static String formatNumber(Number value); static String formatNumberFiveCharLimit(Number value); static String formatMillisOrSeconds(Number value); static String generateDefaultValueMessage(String metric, Number value);  }