LocalDateTimeParser implements DateTimeParser { @Override public Optional<Long> getEpochMilli(final String time) { final LocalDateTime parsed = LocalDateTime.parse(time, DateTimeFormatter.ISO_LOCAL_DATE_TIME); return Optional.of(parsed.atZone(zoneId).toInstant().toEpochMilli()); } LocalDateTimeParser();  LocalDateTimeParser(final ZoneId zoneId); @Override Optional<Long> getEpochMilli(final String time);  }
@Test void shouldParseLocalDateTime() { final Optional<Long> parsed = new LocalDateTimeParser(ZoneOffset.UTC) .getEpochMilli("2017-10-05T10:36:22"); assertThat(parsed) .hasValue(1507199782000L); }
@Test void shouldChangeZone() { final ZoneId pst = ZoneId.of(ZoneId.SHORT_IDS.get("PST")); final Optional<Long> parsed = new LocalDateTimeParser(pst) .getEpochMilli("2017-10-05T10:36:22"); assertThat(parsed) .hasValue(1507199782000L + TimeUnit.HOURS.toMillis(7)); }