Forum     

Go Back   Digit Technology Discussion Forum > Portables, Peripherals and Electronics > QnA (read only)
Register FAQ Calendar Mark Forums Read

QnA (read only) Mods please help transfer the contents of this forum to proper sections. :)


 
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-03-2007, 05:38 PM   #1 (permalink)
In The Zone
 
whoopy_whale's Avatar
 
Join Date: Sep 2004
Location: Bermuda Triangle
Posts: 239
Default 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.
whoopy_whale is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 15-03-2007, 01:03 AM   #2 (permalink)
Back to School Mr. Bean !
 
mod-the-pc's Avatar
 
Join Date: Apr 2004
Location: Chennai
Posts: 343
Default 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.
mod-the-pc is offline  
Old 15-03-2007, 08:10 AM   #3 (permalink)
IM AS MAD AS HELL!!
 
max_demon's Avatar
 
Join Date: Oct 2006
Location: localhost
Posts: 1,618
Default 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!
max_demon is offline  
Old 15-03-2007, 07:14 PM   #4 (permalink)
Back to School Mr. Bean !
 
mod-the-pc's Avatar
 
Join Date: Apr 2004
Location: Chennai
Posts: 343
Default 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
mod-the-pc is offline  
Old 16-03-2007, 09:35 AM   #5 (permalink)
In The Zone
 
whoopy_whale's Avatar
 
Join Date: Sep 2004
Location: Bermuda Triangle
Posts: 239
Default 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.
whoopy_whale is offline  
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by clmlbx
- by abhidev
- by Sarath
- by ico
- by clinton

Advertisement




All times are GMT +5.5. The time now is 02:33 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2