01-03-2007, 05:38 PM
|
#1 (permalink)
|
|
In The Zone
Join Date: Sep 2004
Location: Bermuda Triangle
Posts: 239
|
Finding the second friday of last month
How can I find the date of the second friday of previous month using Java ?
Suggestions please...
__________________
In just two days, tomorrow will be yesterday.
|
|
|
|
Advertisements. Register and be a member of the community to get rid of them.
|
|
Advertisement
|
|
15-03-2007, 01:03 AM
|
#2 (permalink)
|
|
Back to School Mr. Bean !
Join Date: Apr 2004
Location: Chennai
Posts: 343
|
Re: Finding the second friday of last month
I came up with this simple way
Code:
import java.util.*;
class Friday
{
public static void main(String a[])
{
int nthWeek =2, monthsBehind=1;
int weekDay=6; //Sunday=1, Monday=2, ...Friday=6, Saturday=7
System.out.println(getNthWeekDay(monthsBehind, nthWeek,weekDay));
}
static Date getNthWeekDay(int monthsBehind, int nthWeek, int weekDay)
{
GregorianCalendar xMonth=new GregorianCalendar();
//point calendar to n months behind
xMonth.add(Calendar.MONTH,-(monthsBehind));
//select the second week of the month
xMonth.set(Calendar.WEEK_OF_MONTH,nthWeek);
//select the required day of the week
xMonth.set(Calendar.DAY_OF_WEEK,weekDay);
return xMonth.getTime();
}
}
__________________
Desktop: P4 2.8E, Intel 865GBF, 512MB Hynix PC3200, Samsung SV1204H 120GB, Samsung SW-248F, Creative Inspire 4400, Samsung 793MB, Compro PVR/FM, WinLIRC
Laptop: HP Pavilion dv8210us
Last edited by mod-the-pc; 15-03-2007 at 01:33 AM.
|
|
|
15-03-2007, 08:10 AM
|
#3 (permalink)
|
|
IM AS MAD AS HELL!!
Join Date: Oct 2006
Location: localhost
Posts: 1,618
|
Re: Finding the second friday of last month
simeplest way , use calander
__________________
When someone dies in the grip of a powerful rage... a curse is born.
Kayako Saeki: Croakkkkkkkkkkkkkkkkkkkkk!
|
|
|
15-03-2007, 07:14 PM
|
#4 (permalink)
|
|
Back to School Mr. Bean !
Join Date: Apr 2004
Location: Chennai
Posts: 343
|
Re: Finding the second friday of last month
Quote:
|
Originally Posted by max_demon
simeplest way , use calander 
|
Yes that's what I did- the "GregorianCalendar" Class I mean!!!
__________________
Desktop: P4 2.8E, Intel 865GBF, 512MB Hynix PC3200, Samsung SV1204H 120GB, Samsung SW-248F, Creative Inspire 4400, Samsung 793MB, Compro PVR/FM, WinLIRC
Laptop: HP Pavilion dv8210us
|
|
|
16-03-2007, 09:35 AM
|
#5 (permalink)
|
|
In The Zone
Join Date: Sep 2004
Location: Bermuda Triangle
Posts: 239
|
Re: Finding the second friday of last month
Quote:
|
Originally Posted by mod-the-pc
I came up with this simple way
Code:
import java.util.*;
class Friday
{
public static void main(String a[])
{
int nthWeek =2, monthsBehind=1;
int weekDay=6; //Sunday=1, Monday=2, ...Friday=6, Saturday=7
System.out.println(getNthWeekDay(monthsBehind, nthWeek,weekDay));
}
static Date getNthWeekDay(int monthsBehind, int nthWeek, int weekDay)
{
GregorianCalendar xMonth=new GregorianCalendar();
//point calendar to n months behind
xMonth.add(Calendar.MONTH,-(monthsBehind));
//select the second week of the month
xMonth.set(Calendar.WEEK_OF_MONTH,nthWeek);
//select the required day of the week
xMonth.set(Calendar.DAY_OF_WEEK,weekDay);
return xMonth.getTime();
}
}
|
Thanks buddy...
__________________
In just two days, tomorrow will be yesterday.
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|