How to get the week of month using Calendar in Java

1 Answer

0 votes
package javaapplication1;

import java.util.Calendar;

public class JavaApplication1 {

    public static void main(String[] args) {

        Calendar now = Calendar.getInstance();
        
        System.out.println("Today: " + (now.get(Calendar.MONTH) + 1)  + "-"
                           + now.get(Calendar.DATE)
                           + "-"
                           + now.get(Calendar.YEAR));
        
        System.out.println("Week of month: " + now.get(Calendar.WEEK_OF_MONTH));
    }
}

/*

run:

Today: 10-19-2016
Week of month: 4

*/

 



answered Oct 19, 2016 by avibootz
...