Thursday, 15 July 2010

How to get all the 1st and 3rd wednesdays date of every month in the current year using java 1.6 -



How to get all the 1st and 3rd wednesdays date of every month in the current year using java 1.6 -

for current year i.e 2014. starting jan 1st, have 1st , 3rd quarta-feira dates every month ending, dec 31st. using java version 1.6

i have no thought how this.

pseudo code, should started in jodatime:

localdate dt = new localdate(2014, 1, 1); // 1st jan for(loop 12 months){ loop 1 time again find 3rd quarta-feira while(count < 4) { d = d.plusdays(1); if(d.getdayofweek() != datetimeconstants.wednesday){ count++ } // based on count save in hashmap, 1 = 1st, 3 = 3rd each month } d.plusmonth(1); }

and here in new java 8 info time :

for(loop through months){ localdate date = localdate.of(2014, month, 01); temporaladjuster adj = temporaladjusters.next(dayofweek.wednesday); localdate nextwed = date.with(adj); localdate secondwed = nextwed.with(adj); localdate thirdwed = secondwed.with(adj); // save in map }

java date calendar

No comments:

Post a Comment