/** * 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. * The zone and offset will be set based on the time-zone in the clock. * <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, not null */ public static ZonedDateTime 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. * The zone and offset will be set based on the time-zone in the clock. * <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, not null */ public static ZonedDateTime 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. * The offset will be calculated from the specified 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 ZonedDateTime now(ZoneId zone) { return now(Clock.system(zone)); }
/** * 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. * The offset will be calculated from the specified 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 ZonedDateTime now(ZoneId zone) { return now(Clock.system(zone)); }