Java program to find Week of Year

How to find Week of Year:

The following Java program is to find week of the year from Calendar object. Using getInstance() method the current date is obtained from Calendar object and using the below code the week from the calendar is obtained.

Syntax: int week=cal.get(Calendar.WEEK_OF_YEAR);

week.java


package com.candidjava.time;

import java.util.Calendar;
import java.util.Date;

public class Week 
{
public static void main(String[] args) 
{
	Calendar cal=Calendar.getInstance();
	int week=cal.get(Calendar.WEEK_OF_YEAR);
	System.out.println("week of year:" +week);	
}
}

Output:

week of year:2

Leave a Reply

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