Example usage for java.util Calendar DATE

List of usage examples for java.util Calendar DATE

Introduction

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

Prototype

int DATE

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

Click Source Link

Document

Field number for get and set indicating the day of the month.

Usage

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));

    now.add(Calendar.YEAR, 1);//from w ww .j av a  2s .  c  o  m
    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("Current date : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-"
            + now.get(Calendar.YEAR));

    now = Calendar.getInstance();
    now.add(Calendar.YEAR, -100);
    System.out.println("date before 100 years : " + (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));

    String[] strMonths = new String[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct",
            "Nov", "Dec" };
    System.out.println("Current month is : " + strMonths[now.get(Calendar.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 time : " + now.get(Calendar.HOUR_OF_DAY) + ":" + now.get(Calendar.MINUTE) + ":"
            + now.get(Calendar.SECOND));

    now.add(Calendar.HOUR, 10);//w w w  .  j a v a2  s .  c o  m
    System.out.println("New time after adding 10 hours : " + now.get(Calendar.HOUR_OF_DAY) + ":"
            + now.get(Calendar.MINUTE) + ":" + now.get(Calendar.SECOND));
}

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 time : " + now.get(Calendar.HOUR_OF_DAY) + ":" + now.get(Calendar.MINUTE) + ":"
            + now.get(Calendar.SECOND));

    now = Calendar.getInstance();
    now.add(Calendar.HOUR, -3);/*  w ww.  j  a v  a2s  .  c o  m*/
    System.out.println("Time before 3 hours : " + now.get(Calendar.HOUR_OF_DAY) + ":" + now.get(Calendar.MINUTE)
            + ":" + now.get(Calendar.SECOND));
}

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));

    now = Calendar.getInstance();
    now.add(Calendar.DATE, -10);/*from   w  ww. j  av a  2 s  .  c o m*/
    System.out.println("date before 10 days : " + (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));

    // add days to current date using Calendar.add method
    now.add(Calendar.DATE, 1);/*  ww  w  .java2  s.  co  m*/

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

From source file:Main.java

public static void main(String[] args) {
    Date myDate;//from  w w  w.  ja va2  s. c o  m
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.MONTH, 9);
    cal.set(Calendar.DATE, 24);
    cal.set(Calendar.YEAR, 2013);
    cal.set(Calendar.HOUR, 13);
    cal.set(Calendar.MINUTE, 45);
    cal.set(Calendar.SECOND, 52);
    myDate = cal.getTime();
    System.out.println(myDate);
}

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));
}