[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • Last Modified:

java calendar

using the java.util.* package, I was trying to get all the days/date in the current week.
Some thing like:

Monday        April 11
Tuesday       April 12
Wednesday  April 13
Thrusday     April 14
Friday          April 15
Saturday      April 16
Sunday        April 17

And then the next week (if I have a next button) (7 days at a time)
Can somebody please help?

Thanks
keet
0
neokeet
Asked:
neokeet
  • 2
1 Solution
 
CEHJCommented:
           Calendar cal = Calendar.getInstance();
            cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
            for(int i = 0;i < 7;i++) {
                  System.out.println(cal.getTime());
                  cal.add(Calendar.DATE, 1);
            }


Increment the week number by 1 for the following week
0
 
dorothy2Commented:
If you need the dates in the format you listed, use a date formatter like this:

DateFormat formatter = new SimpleDateFormat("EEEE MMMM dd");
System.out.println(formatter.format(cal.getTime()));

Dorothy
0
 
CEHJCommented:
:-)
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now