Close

Java Date Time - LocalTime.getLong() Examples

Java Date Time Java Java API 


Class:

java.time.LocalTime

java.lang.Objectjava.lang.Objectjava.time.LocalTimejava.time.LocalTimejava.time.temporal.TemporalTemporaljava.time.temporal.TemporalAdjusterTemporalAdjusterjava.lang.ComparableComparablejava.io.SerializableSerializableLogicBig

Method:

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.



Examples


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);
}
}

Output

NANO_OF_DAY: 52240000003000
MICRO_OF_DAY: 52240000003




See Also