Open In App

java.time.temporal.WeekFields Class in Java

Last Updated : 17 Mar, 2021
Comments
Improve
Suggest changes
18 Likes
Like
Report

The WeekFields class represents the definition of the week, to provide TemporalField instances. WeekFields provides five fields, weekOfYear(), weekOfMonth(), dayOfWeek(), weekOfWeekBasedYear(), and weekBasedYear() that provide access to the values from any temporal object.

A separate Field instance is required for each different WeekFields and requires:

  • Start of week
  • Minimum number of days

Class declaration:

public final class WeekFields
extends Object
implements Serializable

WeekFields class inherits following methods from class java.lang.Object:

  • clone()
  • finalize()
  • getClass()
  • notify()
  • notifyAll()
  • wait()

Method of WeekFields Class:

MethodDescription
dayOfWeek()This method returns a field to access the day of the week based on this WeekFields.
equals(Object object)This method checks if this WeekFields is equal to the specified object.
getFirstDayOfWeek()This method gets the first day-of-week.
getMinimalDaysInFirstWeek()This method gets a minimal number of days in the first week.
hashCode()This method returns a hash code for this WeekFields.
of(DayOfWeek firstDayOfWeek, int minimalDaysInFirstWeek)This method obtains an instance of WeekFields from the first day-of-week and minimal days.
of(Locale locale)This method obtains an instance of WeekFields appropriate for a locale.
toString()This method gets a string representation of this WeekFields instance.
weekBasedYear()This method returns a field to access the year of a week-based-year based on this WeekFields.
weekOfMonth()This method returns a field to access the week of month based on this WeekFields.
weekOfWeekBasedYear()This method returns a field to access the week of a week-based-year based on this WeekFields.
weekOfYear()This method returns a field to access the week of year based on this WeekFields.

Example 1:


Output
day of week for 2021-03-31 :3
week based year for 2021-03-31 :2021
week of month for 2021-03-31 :5
Week of week for 2021-03-31 :14

Example 2:


Output
day of week for 2021-12-05 :1
week based year for 2021-12-05 :2021
week of month for 2021-12-05 :2
Week of week for 2021-12-05 :50

Next Article
Practice Tags :

Similar Reads