If you want the millisecond of the day (in other words the count of milliseconds since 00:00), there is a ChronoField
enum constant exactly for that:
LocalTime lunchTime = LocalTime.parse("01:00:00");
int millisecondOfDay = lunchTime.get(ChronoField.MILLI_OF_DAY);
System.out.println("Lunch is at " + millisecondOfDay + " milliseconds of the day");
Output:
Lunch is at 3600000 milliseconds of the day
(1 AM is probably a funny time for lunch for some, but for the sake of demonstration and of using your own example.)
The date and time classes of java.time generally have got a get
method that accepts a TemporalField
argument. LocalTime
is no exception to this rule. The most common thing to do when calling get()
is to pass a ChronoField
constant. The method is very versatile for getting values from the date-time object for which no getXxx
method is provided.
Doc link: ChronoField.MILLI_OF_DAY