/** * Obtains the current date-time from the system clock in the specified time-zone. * <p> * This will query the {@link Clock#system(ZoneId) system clock} to obtain the current date-time. * Specifying the time-zone avoids dependence on the default time-zone. * <p> * Using this method will prevent the ability to use an alternate clock for testing * because the clock is hard-coded. * * @param zone the zone ID to use, not null * @return the current date-time using the system clock, not null */ public static LocalDateTime now(ZoneId zone) { return now(Clock.system(zone)); }
/** * Obtains the current date-time from the system clock in the default time-zone. * <p> * This will query the {@link Clock#systemDefaultZone() system clock} in the default * time-zone to obtain the current date-time. * <p> * Using this method will prevent the ability to use an alternate clock for testing * because the clock is hard-coded. * * @return the current date-time using the system clock and default time-zone, not null */ public static LocalDateTime now() { return now(Clock.systemDefaultZone()); }
/** * Obtains the current date-time from the system clock in the default time-zone. * <p> * This will query the {@link Clock#systemDefaultZone() system clock} in the default * time-zone to obtain the current date-time. * <p> * Using this method will prevent the ability to use an alternate clock for testing * because the clock is hard-coded. * * @return the current date-time using the system clock and default time-zone, not null */ public static LocalDateTime now() { return now(Clock.systemDefaultZone()); }
/** * Obtains the current date-time from the system clock in the specified time-zone. * <p> * This will query the {@link Clock#system(ZoneId) system clock} to obtain the current date-time. * Specifying the time-zone avoids dependence on the default time-zone. * <p> * Using this method will prevent the ability to use an alternate clock for testing * because the clock is hard-coded. * * @param zone the zone ID to use, not null * @return the current date-time using the system clock, not null */ public static LocalDateTime now(ZoneId zone) { return now(Clock.system(zone)); }
private Duration getDifferenceBetweenTimeAndNow(long timeStart) { LocalDateTime today = LocalDateTime.now(); LocalDateTime otherTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(timeStart), ZoneId.systemDefault()); return Duration.between(otherTime, today); }
startDate = zoneOffsetTransition.getDateTimeBefore(); } else { startDate = LocalDateTime.now(zoneId); int transitionRuleMonthValue = transitionRule.getMonth().getValue(); DayOfWeek transitionRuleDayOfWeek = transitionRule.getDayOfWeek(); LocalDateTime ldt = LocalDateTime.now(zoneId) .with(TemporalAdjusters.firstInMonth(transitionRuleDayOfWeek)) .withMonth(transitionRuleMonthValue)