- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get week of month and year using Java Calendar
For using Calendar class, import the following package.
import java.util.Calendar;
Create a Calendar class object.
Calendar cal = Calendar.getInstance();
Now, get the week of month and year using the following fields.
Calendar.WEEK_OF_MONTH Calendar.WEEK_OF_YEAR
The following is an example.
Example
import java.util.Calendar; public class Demo { public static void main(String[] args) { Calendar cal = Calendar.getInstance(); // current date and time System.out.println(cal.getTime().toString()); // date information System.out.println("
Date Information.........."); System.out.println("Year = " + cal.get(Calendar.YEAR)); System.out.println("Month = " + (cal.get(Calendar.MONTH) + 1)); System.out.println("Date = " + cal.get(Calendar.DATE)); // week System.out.println("Week of month = " + cal.get(Calendar.WEEK_OF_MONTH)); System.out.println("Week of year = " + cal.get(Calendar.WEEK_OF_YEAR)); // time information System.out.println("
Time Information.........."); System.out.println("Hour (24 hour format) : " + cal.get(Calendar.HOUR_OF_DAY)); System.out.println("Hour (12 hour format) : " + cal.get(Calendar.HOUR)); System.out.println("Minute : " + cal.get(Calendar.MINUTE)); System.out.println("Second : " + cal.get(Calendar.SECOND)); System.out.println("Millisecond : " + cal.get(Calendar.MILLISECOND)); } }
Output
Mon Nov 19 14:28:46 UTC 2018 Date Information.......... Year = 2018 Month = 11 Date = 19 Week of month = 4 Week of year = 47 Time Information.......... Hour (24 hour format) : 14 Hour (12 hour format) : 2 Minute : 28 Second : 46 Millisecond : 464
- Related Articles
- Display Month of Year using Java Calendar
- Determine day of week in month from Gregorian Calendar in Java
- How to get month from week number and year in Excel?
- Display Day Name of Week using Java Calendar
- Java Program to get current date, year and month
- How to get day of month, day of year and day of week in android using offset date time API class?
- Increment a Month using the Calendar Class in Java
- Decrement a Month using the Calendar Class in Java
- How to get current day, month and year in Java 8?
- Finding day of week from date (day, month, year) in JavaScript
- How to get a Date from year, month and day in Java?
- Get time in milliseconds using Java Calendar
- Calendar Functions in Python - ( calendar(), month(), isleap()?)
- Write the difference between calendar year and fiscal year.
- Java Program to get day of week for the last day of each month in 2019

Advertisements