Java Date Time Java Java API
java.time.LocalTime
public long getLong(TemporalField field)
This method extracts and returns the specified temporal field value as long.
This method is different from get(TemporalField) in that, it won't throw UnsupportedTemporalTypeException for fields NANO_OF_DAY and MICRO_OF_DAY.
This method will also throw the exception for the field which returns false from LocalTime.isSupported(TemporalField) method.
LocalTime.isSupported(TemporalField)
package com.logicbig.example.localtime;import java.time.LocalTime;import java.time.temporal.ChronoField;public class GetLongExample { public static void main (String... args) { LocalTime d = LocalTime.of(14, 30, 40, 3000); long i = d.getLong(ChronoField.NANO_OF_DAY); System.out.printf("NANO_OF_DAY: %d%n", i); i = d.getLong(ChronoField.MICRO_OF_DAY); System.out.printf("MICRO_OF_DAY: %d%n", i); }}
NANO_OF_DAY: 52240000003000MICRO_OF_DAY: 52240000003