java.time – Year


java.time.Year Class


”;


Introduction

The java.time.Year class represents a year in the ISO-8601 calendar system, such as 2007.

Class declaration

Following is the declaration for java.time.Year class −

public final class Year
   extends Object
      implements Temporal, TemporalAdjuster, Comparable<Year>, Serializable

Field

Following are the fields for Java.time.Period class −

  • static int MAX_VALUE − The maximum supported year, ”+999,999,999”.

  • static int MIN_VALUE − The minimum supported year, ”-999,999,999”.

Class methods

Sr.No. Method & Description
1 Temporal adjustInto(Temporal temporal)

Adjusts the specified temporal object to have this year.

2 LocalDate atDay(int dayOfYear)

Combines this year with a day-of-year to create a LocalDate.

3

YearMonth atMonth(int month)

Combines this year with a month to create a YearMonth.

4

YearMonth atMonth(Month month)

Combines this year with a month to create a YearMonth.

5

LocalDate atMonthDay(MonthDay monthDay)

Combines this year with a month-day to create a LocalDate.

6 int compareTo(Year other)

Compares this year to another year.

7 boolean equals(Object otherYear)

Checks if this Year is equal to the specified Year.

8 String format(DateTimeFormatter formatter)

Formats this year using the specified formatter.

9 static Year from(TemporalAmount amount)

Obtains an instance of Year from a temporal amount.

10 int get(TemporalField field)

Gets the value of the specified field from this year as an int.

11 long getLong(TemporalField field)

Gets the value of the requested unit as long.

12 int getValue()

Gets the year value.

13 int hashCode()

A hash code for this Year.

14 boolean isAfter(Year other)

Checks if this year is after the specified year.

15 boolean isBefore(Year other)

Checks if this year is before the specified year.

16 boolean isLeap()

Checks if the year is a leap year, according to the ISO proleptic calendar system rules.

17 boolean isLeap(long year)

Checks if the year is a leap year, according to the ISO proleptic calendar system rules.

18 boolean isSupported(TemporalField field)

Checks if the specified field is supported.

19 boolean isSupported(TemporalUnit unit)

Checks if the specified unit is supported.

20 boolean isValidMonthDay(MonthDay monthDay)

Checks if the month-day is valid for this year.

21 int length()

Gets the length of this year in days.

22 Year minus(long amountToSubtract, TemporalUnit unit)

Returns a copy of this year with the specified amount subtracted.

23 Year minus(TemporalAmount amountToSubtract)

Returns a copy of this Year with the specified Year subtracted.

24 Year minusYears(long yearsToSubtract)

Returns a copy of this Year with the specified years subtracted.

25 static Year now()

Obtains the current year from the system clock in the default time-zone.

26 static Year now(Clock clock)

Obtains the current year from the specified clock.

27 static Year now(ZoneId zone)

Obtains the current year from the system clock in the specified time-zone.

28 static Year of(int years)

Obtains an instance of Year.

29 static Year parse(CharSequence text)

Obtains a Year from a text string such as 2007.

30 static Year parse(CharSequence text, DateTimeFormatter formatter)

Obtains an instance of Year from a text string using a specific formatter.

31 Year plus(long amountToAdd, TemporalUnit unit)

Returns a copy of this Year with the specified Year added.

32 Year plus(TemporalAmount amountToAdd)

Returns a copy of this Year with the specified Year added.

33

Year plusMonths(long monthsToAdd)

Returns a copy of this Year with the specified months added.

34 Year plusYears(long yearsToAdd)

Returns a copy of this Year with the specified years added.

35 <R> R query(TemporalQuery<R> query)

Queries this year using the specified query.

36 ValueRange range(TemporalField field)

Gets the range of valid values for the specified field.

37 String toString()

Outputs this year as a String.

38 long until(Temporal endExclusive, TemporalUnit unit)

Calculates the amount of time until another year in terms of the specified unit.

39 Year with(TemporalAdjuster adjuster)

Returns an adjusted copy of this year.

Methods inherited

This class inherits methods from the following classes −

  • Java.lang.Object

Advertisements

”;

Leave a Reply

Your email address will not be published. Required fields are marked *