These are the variants available in LocalTime
, notice MIDNIGHT
and MIN
are equal.
LocalDate.now().atTime(LocalTime.MIDNIGHT); //00:00:00.000000000
LocalDate.now().atTime(LocalTime.MIN); //00:00:00.000000000
LocalDate.now().atTime(LocalTime.NOON); //12:00:00.000000000
LocalDate.now().atTime(LocalTime.MAX); //23:59:59.999999999
For reference, this is the implementation in java.time.LocalTime
/**
* Constants for the local time of each hour.
*/
private static final LocalTime[] HOURS = new LocalTime[24];
static {
for (int i = 0; i < HOURS.length; i++) {
HOURS[i] = new LocalTime(i, 0, 0, 0);
}
MIDNIGHT = HOURS[0];
NOON = HOURS[12];
MIN = HOURS[0];
MAX = new LocalTime(23, 59, 59, 999_999_999);
}
If the value assigned to the 4th constructor argument (999_999_999
) of LocalTime
(representing nanoOfSecond
) looks unfamiliar it's because it's making use of the Java 7 feature Underscores in Numeric Literals.
In Java SE 7 and later, any number of underscore characters (_) can appear anywhere between digits in a numerical literal. This feature enables you, for example, to separate groups of digits in numeric literals, which can improve the readability of your code.