Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

java code to get the date of second sunday of march of every year

Hi all,

i need some java code to get date of second sunday in march and first sunday in november of every year.

this is very urgent

plz help

thanks in advance

jhansi

Former Member
Former Member replied

Maybe this one is a little bit easier

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

public class Test {

	public static void main (String args[]) {
	
		System.out.println (getSecondSundayOfMarch());
		System.out.println (getFirstSundayOfNovember());
		
	}

	public static final Date getSecondSundayOfMarch () {
		
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.MONTH, Calendar.MARCH);
		cal.setFirstDayOfWeek(Calendar.SUNDAY);
		cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
		cal.set(Calendar.WEEK_OF_MONTH,2);
		return cal.getTime();
	}
	
	public static final Date getFirstSundayOfNovember () {
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.MONTH, Calendar.NOVEMBER);
		cal.setFirstDayOfWeek(Calendar.SUNDAY);
		cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
		cal.set(Calendar.WEEK_OF_MONTH,1);
		return cal.getTime();
	}
	
}

regards franz

reward points if useful

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question