Close

Java Date Time - Year.getLong() Examples

Java Date Time Java Java API 


Class:

java.time.Year

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

Method:

public long getLong(TemporalField field)

The method returns the value of the specified field from this year as a long value.


Examples


package com.logicbig.example.year;

import java.time.Year;
import java.time.temporal.ChronoField;
import java.time.temporal.UnsupportedTemporalTypeException;

public class GetLongExample {

public static void main(String... args) {
Year y = Year.of(2011);
System.out.println(y);

for (ChronoField field : ChronoField.values()) {
try {
long l = y.getLong(field);
System.out.printf("%12s > %s%n", field, l);
} catch (UnsupportedTemporalTypeException e) {
System.out.printf(" -- %s not supported%n", field);
}
}
}
}

Output

2011
-- NanoOfSecond not supported
-- NanoOfDay not supported
-- MicroOfSecond not supported
-- MicroOfDay not supported
-- MilliOfSecond not supported
-- MilliOfDay not supported
-- SecondOfMinute not supported
-- SecondOfDay not supported
-- MinuteOfHour not supported
-- MinuteOfDay not supported
-- HourOfAmPm not supported
-- ClockHourOfAmPm not supported
-- HourOfDay not supported
-- ClockHourOfDay not supported
-- AmPmOfDay not supported
-- DayOfWeek not supported
-- AlignedDayOfWeekInMonth not supported
-- AlignedDayOfWeekInYear not supported
-- DayOfMonth not supported
-- DayOfYear not supported
-- EpochDay not supported
-- AlignedWeekOfMonth not supported
-- AlignedWeekOfYear not supported
-- MonthOfYear not supported
-- ProlepticMonth not supported
YearOfEra > 2011
Year > 2011
Era > 1
-- InstantSeconds not supported
-- OffsetSeconds not supported




See Also