@Test public void convert() { ZonedDateTime zdt = ZoneDateTimeUtils.truncatedTo(Instant.ofEpochSecond(1546041600).atZone(ZoneOffset.UTC), ChronoUnit.DAYS); assertEquals(1546041600, zdt.toInstant().getEpochSecond()); }
public static ZonedDateTime truncatedTo(ZonedDateTime zonedDateTime, ChronoUnit chronoUnit) { switch (chronoUnit) { case WEEKS: return zonedDateTime.truncatedTo(ChronoUnit.DAYS).with(DayOfWeek.MONDAY); case MONTHS: return zonedDateTime.truncatedTo(ChronoUnit.DAYS).withDayOfMonth(1); case YEARS: return zonedDateTime.truncatedTo(ChronoUnit.DAYS).withDayOfMonth(1).withMonth(1); default: return zonedDateTime.truncatedTo(chronoUnit); } }
ZoneDateTimeUtils { public static ZonedDateTime truncatedTo(ZonedDateTime zonedDateTime, ChronoUnit chronoUnit) { switch (chronoUnit) { case WEEKS: return zonedDateTime.truncatedTo(ChronoUnit.DAYS).with(DayOfWeek.MONDAY); case MONTHS: return zonedDateTime.truncatedTo(ChronoUnit.DAYS).withDayOfMonth(1); case YEARS: return zonedDateTime.truncatedTo(ChronoUnit.DAYS).withDayOfMonth(1).withMonth(1); default: return zonedDateTime.truncatedTo(chronoUnit); } } }
ZoneDateTimeUtils { public static ZonedDateTime truncatedTo(ZonedDateTime zonedDateTime, ChronoUnit chronoUnit) { switch (chronoUnit) { case WEEKS: return zonedDateTime.truncatedTo(ChronoUnit.DAYS).with(DayOfWeek.MONDAY); case MONTHS: return zonedDateTime.truncatedTo(ChronoUnit.DAYS).withDayOfMonth(1); case YEARS: return zonedDateTime.truncatedTo(ChronoUnit.DAYS).withDayOfMonth(1).withMonth(1); default: return zonedDateTime.truncatedTo(chronoUnit); } }  }
ZoneDateTimeUtils { public static ZonedDateTime truncatedTo(ZonedDateTime zonedDateTime, ChronoUnit chronoUnit) { switch (chronoUnit) { case WEEKS: return zonedDateTime.truncatedTo(ChronoUnit.DAYS).with(DayOfWeek.MONDAY); case MONTHS: return zonedDateTime.truncatedTo(ChronoUnit.DAYS).withDayOfMonth(1); case YEARS: return zonedDateTime.truncatedTo(ChronoUnit.DAYS).withDayOfMonth(1).withMonth(1); default: return zonedDateTime.truncatedTo(chronoUnit); } }  static ZonedDateTime truncatedTo(ZonedDateTime zonedDateTime, ChronoUnit chronoUnit); }
ZoneDateTimeUtils { public static ZonedDateTime truncatedTo(ZonedDateTime zonedDateTime, ChronoUnit chronoUnit) { switch (chronoUnit) { case WEEKS: return zonedDateTime.truncatedTo(ChronoUnit.DAYS).with(DayOfWeek.MONDAY); case MONTHS: return zonedDateTime.truncatedTo(ChronoUnit.DAYS).withDayOfMonth(1); case YEARS: return zonedDateTime.truncatedTo(ChronoUnit.DAYS).withDayOfMonth(1).withMonth(1); default: return zonedDateTime.truncatedTo(chronoUnit); } }  static ZonedDateTime truncatedTo(ZonedDateTime zonedDateTime, ChronoUnit chronoUnit);  }