Open In App

WeekFields weekBasedYear() method in Java with Examples

Last Updated : 29 Jan, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The weekBasedYear() method of WeekFields class is used to return a field to access the year of a week-based-year based on this WeekFields.This field can be used with any calendar system.

Syntax:

public TemporalField weekBasedYear()

Parameters: This method accepts nothing.

Return value: This method returns a field providing access to the week-based-year, not null.

Below programs illustrate the WeekFields.weekBasedYear() method:
Program 1:




// Java program to demonstrate
// WeekFields.weekBasedYear() method
  
import java.time.DayOfWeek;
import java.time.temporal.TemporalField;
import java.time.temporal.WeekFields;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create WeekFields
        WeekFields weekFields
            = WeekFields.of(DayOfWeek.MONDAY, 1);
  
        // apply weekBasedYear()
        TemporalField weekBasedYear
            = weekFields.weekBasedYear();
  
        // print results
        System.out.println(weekBasedYear);
    }
}


Output:

WeekBasedYear[WeekFields[MONDAY, 1]]

Program 2:




// Java program to demonstrate
// WeekFields.weekBasedYear() method
  
import java.time.DayOfWeek;
import java.time.temporal.TemporalField;
import java.time.temporal.WeekFields;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create WeekFields
        WeekFields weekFields
            = WeekFields.of(DayOfWeek.SUNDAY, 1);
  
        // apply weekBasedYear()
        TemporalField weekBasedYear
            = weekFields.weekBasedYear();
  
        // print results
        System.out.println(weekBasedYear);
    }
}


Output:

WeekBasedYear[WeekFields[SUNDAY, 1]]

References: https://docs.oracle.com/javase/10/docs/api/java/time/temporal/WeekFields.html#weekBasedYear()



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads