- Java.util Package Classes
- Java.util - Home
- Java.util - ArrayDeque
- Java.util - ArrayList
- Java.util - Arrays
- Java.util - BitSet
- Java.util - Calendar
- Java.util - Collections
- Java.util - Currency
- Java.util - Date
- Java.util - Dictionary
- Java.util - EnumMap
- Java.util - EnumSet
- Java.util - Formatter
- Java.util - GregorianCalendar
- Java.util - HashMap
- Java.util - HashSet
- Java.util - Hashtable
- Java.util - IdentityHashMap
- Java.util - LinkedHashMap
- Java.util - LinkedHashSet
- Java.util - LinkedList
- Java.util - ListResourceBundle
- Java.util - Locale
- Java.util - Observable
- Java.util - PriorityQueue
- Java.util - Properties
- Java.util - PropertyPermission
- Java.util - PropertyResourceBundle
- Java.util - Random
- Java.util - ResourceBundle
- Java.util - ResourceBundle.Control
- Java.util - Scanner
- Java.util - ServiceLoader
- Java.util - SimpleTimeZone
- Java.util - Stack
- Java.util - StringTokenizer
- Java.util - Timer
- Java.util - TimerTask
- Java.util - TimeZone
- Java.util - TreeMap
- Java.util - TreeSet
- Java.util - UUID
- Java.util - Vector
- Java.util - WeakHashMap
- Java.util Package Extras
- Java.util - Interfaces
- Java.util - Exceptions
- Java.util - Enumerations
- Java.util Useful Resources
- Java.util - Useful Resources
- Java.util - Discussion
Java GregorianCalendar setWeekDate() Method
Description
The Java GregorianCalendar setWeekDate(int weekYear, int weekOfYear, int dayOfWeek) method sets this GregorianCalendar to the date given by the date specifiers - weekYear, weekOfYear, and dayOfWeek. weekOfYear follows the WEEK_OF_YEAR numbering. The dayOfWeek value must be one of the DAY_OF_WEEK values: SUNDAY to SATURDAY.
Declaration
Following is the declaration for java.util.GregorianCalendar.setGregorianChange(int weekYear, int weekOfYear, int dayOfWeek) method
public void setWeekDate​(int weekYear, int weekOfYear, int dayOfWeek)
Parameters
weekYear − the week year.
weekOfYear − the week number based on weekYear.
dayOfWeek − the day of week value: one of the constants for the DAY_OF_WEEK field: SUNDAY, ..., SATURDAY.
Return Value
This method does not return a value.
Exception
IllegalArgumentException − if any of the given date specifiers is invalid, or if any of the calendar fields are inconsistent with the given date specifiers in non-lenient mode.
Setting a Week Date in Current Dated GregorianCalendar Example
The following example shows the usage of Java GregorianCalendar setWeekDate() method. We're creating a GregorianCalendar instance of current date. We've modified calendar using setWeekDate() method and then printed the same.
package com.tutorialspoint; import java.util.GregorianCalendar; public class GregorianCalendarDemo { public static void main(String[] args) { // create a new calendar GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance(); // print the current date and time System.out.println("" + cal.getTime()); // set week date change at another date cal.setWeekDate(2022, 12, GregorianCalendar.SUNDAY); System.out.println("Date: " + cal.getTime()); } }
Output
Let us compile and run the above program, this will produce the following result −
Mon Apr 29 14:05:58 IST 2024 Date: Sun Mar 13 14:05:58 IST 2022
Setting a Week Date an Year Ahead in Current Dated GregorianCalendar Example
The following example shows the usage of Java GregorianCalendar setWeekDate() method. We're creating a GregorianCalendar instance of current date. We've modified calendar using setWeekDate() method and then printed the same.
package com.tutorialspoint; import java.util.GregorianCalendar; public class GregorianCalendarDemo { public static void main(String[] args) { // create a new calendar GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance(); // print the current date and time System.out.println("" + cal.getTime()); // set week date change at another date cal.setWeekDate(2022, 56, GregorianCalendar.SUNDAY); System.out.println("Date: " + cal.getTime()); } }
Output
Let us compile and run the above program, this will produce the following result −
Mon Apr 29 14:06:44 IST 2024 Date: Sun Jan 15 14:06:44 IST 2023
To Continue Learning Please Login
Login with Google