Example usage for java.util Calendar WEEK_OF_MONTH

List of usage examples for java.util Calendar WEEK_OF_MONTH

Introduction

In this page you can find the example usage for java.util Calendar WEEK_OF_MONTH.

Prototype

int WEEK_OF_MONTH

To view the source code for java.util Calendar WEEK_OF_MONTH.

Click Source Link

Document

Field number for get and set indicating the week number within the current month.

Usage

From source file:Main.java

public static void main(String[] args) {
    Calendar now = Calendar.getInstance();

    System.out.println("Current week of month is : " + now.get(Calendar.WEEK_OF_MONTH));
    System.out.println("Current week of year is : " + now.get(Calendar.WEEK_OF_YEAR));

    now.add(Calendar.WEEK_OF_MONTH, 1);

    System.out.println("date after one year : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE)
            + "-" + now.get(Calendar.YEAR));
}

From source file:Main.java

public static void main(String[] args) {
    Calendar now = Calendar.getInstance();
    System.out.println(now.getTime());

    System.out.println(now.get(Calendar.WEEK_OF_MONTH));

}

From source file:Main.java

public static void main(String[] args) {
    Calendar now = Calendar.getInstance();

    System.out.println("Current date : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-"
            + now.get(Calendar.YEAR));

    System.out.println("Current week of month is : " + now.get(Calendar.WEEK_OF_MONTH));
    System.out.println("Current week of year is : " + now.get(Calendar.WEEK_OF_YEAR));

    now.add(Calendar.WEEK_OF_YEAR, 1);
    System.out.println("date after one week : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE)
            + "-" + now.get(Calendar.YEAR));
}

From source file:Main.java

public static void main(String[] args) {
    Calendar now = Calendar.getInstance();

    System.out.println("Current date : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-"
            + now.get(Calendar.YEAR));

    System.out.println("Current week of month is : " + now.get(Calendar.WEEK_OF_MONTH));
    System.out.println("Current week of year is : " + now.get(Calendar.WEEK_OF_YEAR));

    now = Calendar.getInstance();
    now.add(Calendar.WEEK_OF_YEAR, -50);
    System.out.println("date before 50 weeks : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE)
            + "-" + now.get(Calendar.YEAR));
}

From source file:MainClass.java

public static void main(String args[]) {
    GregorianCalendar gc = new GregorianCalendar();
    int year = gc.get(Calendar.YEAR);
    System.out.println(year);//from   ww w . j  av a2  s .c  om
    System.out.println(gc.isLeapYear(year));
    System.out.println("Month = " + gc.get(Calendar.MONTH));
    System.out.println("Week of year = " + gc.get(Calendar.WEEK_OF_YEAR));
    System.out.println("Week of month = " + gc.get(Calendar.WEEK_OF_MONTH));
    System.out.println("Day of year = " + gc.get(Calendar.DAY_OF_YEAR));
    System.out.println("Day of week = " + gc.get(Calendar.DAY_OF_WEEK));
}

From source file:MainClass.java

public static void main(String[] a) {
    Calendar calendar = new GregorianCalendar();
    calendar.setTime(new Date());

    System.out.println("ERA: " + calendar.get(Calendar.ERA));
    System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
    System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
    System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));
    System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));
    System.out.println("DATE: " + calendar.get(Calendar.DATE));
    System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));
    System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));
    System.out.println("DAY_OF_WEEK_IN_MONTH: " + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));
    System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM));
    System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));
    System.out.println("ZONE_OFFSET: " + (calendar.get(Calendar.ZONE_OFFSET) / (60 * 60 * 1000)));
    System.out.println("DST_OFFSET: " + (calendar.get(Calendar.DST_OFFSET) / (60 * 60 * 1000)));
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Spinning");
    Container contentPane = frame.getContentPane();
    String months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September",
            "October", "November", "December" };
    SpinnerModel model = new SpinnerListModel(months);
    JSpinner spinner = new JSpinner(model);
    contentPane.add(spinner, BorderLayout.NORTH);

    SpinnerDateModel model2 = new SpinnerDateModel();
    model2.setCalendarField(Calendar.WEEK_OF_MONTH);
    JSpinner spinner2 = new JSpinner(model2);
    JSpinner.DateEditor editor2 = new JSpinner.DateEditor(spinner2, "MMMMM dd, yyyy");
    spinner2.setEditor(editor2);//from  w ww . ja v a2  s .c o  m
    frame.getContentPane().add(spinner2, BorderLayout.CENTER);

    SpinnerNumberModel model3 = new SpinnerNumberModel(50, 0, 100, 5);
    JSpinner spinner3 = new JSpinner(model3);
    frame.getContentPane().add(spinner3, BorderLayout.SOUTH);

    frame.setSize(200, 100);
    frame.setVisible(true);
}

From source file:SpinnerTest.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Spinning");
    Container contentPane = frame.getContentPane();
    String months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September",
            "October", "November", "December" };
    SpinnerModel model = new SpinnerListModel(months);
    JSpinner spinner = new JSpinner(model);
    contentPane.add(spinner, BorderLayout.NORTH);

    SpinnerDateModel model2 = new SpinnerDateModel();
    model2.setCalendarField(Calendar.WEEK_OF_MONTH);
    JSpinner spinner2 = new JSpinner(model2);
    JSpinner.DateEditor editor2 = new JSpinner.DateEditor(spinner2, "MMMMM dd, yyyy");
    spinner2.setEditor(editor2);//from   w  ww . j ava2s . c  o m
    frame.getContentPane().add(spinner2, BorderLayout.CENTER);

    SpinnerNumberModel model3 = new SpinnerNumberModel(50, 0, 100, 5);
    JSpinner spinner3 = new JSpinner(model3);
    frame.getContentPane().add(spinner3, BorderLayout.SOUTH);

    frame.setSize(200, 100);
    frame.show();
}

From source file:DayWeek.java

public static void main(String[] av) {
    //+//from ww w. j  ava  2s .  c om
    Calendar c = Calendar.getInstance(); // today

    System.out.println("Year: " + c.get(Calendar.YEAR));
    System.out.println("Month: " + c.get(Calendar.MONTH));
    System.out.println("Day: " + c.get(Calendar.DAY_OF_MONTH));
    System.out.println("Day of week = " + c.get(Calendar.DAY_OF_WEEK));
    System.out.println("Day of year = " + c.get(Calendar.DAY_OF_YEAR));
    System.out.println("Week in Year: " + c.get(Calendar.WEEK_OF_YEAR));
    System.out.println("Week in Month: " + c.get(Calendar.WEEK_OF_MONTH));
    System.out.println("Day of Week in Month: " + c.get(Calendar.DAY_OF_WEEK_IN_MONTH));
    System.out.println("Hour: " + c.get(Calendar.HOUR));
    System.out.println("AM or PM: " + c.get(Calendar.AM_PM));
    System.out.println("Hour (24-hour clock): " + c.get(Calendar.HOUR_OF_DAY));
    System.out.println("Minute: " + c.get(Calendar.MINUTE));
    System.out.println("Second: " + c.get(Calendar.SECOND));
    //-
}

From source file:Main.java

public static int getTotalWeeks(Calendar calendar) {
    if (null == calendar)
        return 0;
    int maxWeeks = calendar.getActualMaximum(Calendar.WEEK_OF_MONTH);
    return maxWeeks;

}