Close

Java Date Time - LocalDateTime.getLong() Examples

Java Date Time Java Java API 


Class:

java.time.LocalDateTime

java.lang.Objectjava.lang.Objectjava.time.LocalDateTimejava.time.LocalDateTimejava.time.temporal.TemporalTemporaljava.time.temporal.TemporalAdjusterTemporalAdjusterjava.time.chrono.ChronoLocalDateTimeChronoLocalDateTimejava.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, MICRO_OF_DAY, EPOCH_DAY and PROLEPTIC_MONTH.

This method will also throw the exception for the field which returns false from LocalDateTime.isSupported(TemporalField) method.



Examples


package com.logicbig.example.localdatetime;

import java.time.LocalDateTime;
import java.time.Month;
import java.time.temporal.ChronoField;

public class GetLongExample {

public static void main (String... args) {
LocalDateTime d = LocalDateTime.of(2010, Month.AUGUST, 10,
20, 10, 23, 100);

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

i = d.getLong(ChronoField.EPOCH_DAY);
System.out.printf("EPOCH_DAY: %d%n", i);

i = d.getLong(ChronoField.PROLEPTIC_MONTH);
System.out.printf("PROLEPTIC_MONTH: %d%n", i);
}
}

Output

NANO_OF_DAY: 72623000000100
MICRO_OF_DAY: 72623000000
EPOCH_DAY: 14831
PROLEPTIC_MONTH: 24127




See Also