Example usage for java.util Calendar YEAR

List of usage examples for java.util Calendar YEAR

Introduction

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

Prototype

int YEAR

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

Click Source Link

Document

Field number for get and set indicating the year.

Usage

From source file:Main.java

public static void main(String[] args) {

    Calendar cal = Calendar.getInstance();

    // print current year
    System.out.println("Current year is :" + cal.get(Calendar.YEAR));

    // set the year to something else
    cal.set(Calendar.YEAR, 2013);

    // print the result
    System.out.println("Altered year is :" + cal.get(Calendar.YEAR));
}

From source file:Main.java

public static void main(String[] args) {

    Calendar cal = Calendar.getInstance();

    // get the maximum value that year field can have
    int i = cal.getActualMaximum(Calendar.YEAR);
    System.out.println("Maximum year:" + i);

    // get the maximum value that month field can have
    int a = cal.getActualMaximum(Calendar.MONTH);
    System.out.println("Maximum month:" + a);
}

From source file:Main.java

public static void main(String[] args) {

    Calendar cal = Calendar.getInstance();

    // return the minimum value that the year field could have
    int i = cal.getActualMinimum(Calendar.YEAR);
    System.out.println("Minimum Year :" + i);

    // returns the minimum value that the month field could have
    int a = cal.getActualMinimum(Calendar.MONTH);
    System.out.println("Minimum month :" + a);
}

From source file:MainClass.java

public static void main(String args[]) {

    Calendar calendar = Calendar.getInstance();
    System.out.println(calendar.get(Calendar.YEAR));
    System.out.println(calendar.get(Calendar.HOUR));
    System.out.println(calendar.get(Calendar.HOUR_OF_DAY));
    System.out.println(calendar.get(Calendar.MINUTE));
}

From source file:Main.java

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

    System.out.println("Today : " + cal.getTime());

    // Subtract 1 year from the calendar
    cal.add(Calendar.YEAR, -1);
    System.out.println("1 year ago: " + cal.getTime());
}

From source file:Main.java

public static void main(String[] args) {

    Calendar cal = Calendar.getInstance();

    // get the value of all the calendar date fields.
    System.out.println("Calendar's Year: " + cal.get(Calendar.YEAR));
    System.out.println("Calendar's Month: " + cal.get(Calendar.MONTH));
    System.out.println("Calendar's Day: " + cal.get(Calendar.DATE));
}

From source file:Main.java

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

    System.out.println("Today : " + cal.getTime());

    // Substract 1 year from the calendar
    cal.add(Calendar.YEAR, -1);
    System.out.println("1 year ago: " + cal.getTime());
}

From source file:Main.java

public static void main(String[] args) {
    GregorianCalendar gc = new GregorianCalendar();
    // current year value
    int year = gc.get(Calendar.YEAR);
    System.out.println(year);//w ww .j  a  v  a  2s.co m
    // current month value
    int month = gc.get(Calendar.MONTH);
    System.out.println(month);
    // day of month
    int day = gc.get(Calendar.DAY_OF_MONTH);
    System.out.println(day);
    // hour value
    int hour = gc.get(Calendar.HOUR);
    System.out.println(hour);
    // minute value
    int minute = gc.get(Calendar.MINUTE);
    System.out.println(minute);
    // second values
    int second = gc.get(Calendar.SECOND);
    System.out.println(second);
}

From source file:Main.java

public static void main(String[] args) {
    Calendar cal = new GregorianCalendar(1999, 1, 1);
    Calendar now = new GregorianCalendar();
    int res = now.get(Calendar.YEAR) - cal.get(Calendar.YEAR);
    if ((cal.get(Calendar.MONTH) > now.get(Calendar.MONTH))
            || (cal.get(Calendar.MONTH) == now.get(Calendar.MONTH)
                    && cal.get(Calendar.DAY_OF_MONTH) > now.get(Calendar.DAY_OF_MONTH))) {
        res--;/* ww w  .j  a  v  a2  s .  c  om*/
    }
    System.out.println(res);
}

From source file:MainClass.java

public static void main(String[] a) {
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY);
    calendar.add(Calendar.YEAR, -14);
    System.out.println(calendar.get(Calendar.YEAR));
}