JAVA Calendar - How to check if it's Saturday/Sunday ?

Posted by Cristian on Stack Overflow See other posts from Stack Overflow or by Cristian
Published on 2011-01-09T01:47:54Z Indexed on 2011/01/09 1:53 UTC
Read the original article Hit count: 536

Filed under:
|
|

What this code does is print the dates of the current week from Monday to Friday. It works fine, but I want to ask something else: If today is Saturday or Sunday I want it to show the next week... how do I do that?

Here's my working code so far (thanks to StackOverflow!!): // Get calendar set to current date and time Calendar c = Calendar.getInstance();

    // Set the calendar to monday of the current week
    c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);

    // Print dates of the current week starting on Monday to Friday
    DateFormat df = new SimpleDateFormat("EEE dd/MM/yyyy");
    for (int i = 0; i <= 4; i++) {
        System.out.println(df.format(c.getTime()));
        c.add(Calendar.DATE, 1);

Thanks a lot! I really appreciate it as I've been searching for the solution for hours...

© Stack Overflow or respective owner

Related posts about java

Related posts about calendar