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 cal = Calendar.getInstance();
    System.out.println("Now : " + cal.getTime());

    int daysToIncrement = 5;

    cal.add(Calendar.DATE, daysToIncrement);
    System.out.println("Date after increment: " + cal.getTime());

}

From source file:Main.java

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

    System.out.println("Current full date time is : " + (now.get(Calendar.MONTH) + 1) + "-"
            + now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR) + " " + now.get(Calendar.HOUR_OF_DAY) + ":"
            + now.get(Calendar.MINUTE) + ":" + now.get(Calendar.SECOND) + "." + now.get(Calendar.MILLISECOND));
}

From source file:Main.java

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

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

    // Subtract 30 days from the calendar
    cal.add(Calendar.DATE, -30);
    System.out.println("30 days ago: " + cal.getTime());

}

From source file:Main.java

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

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

    // Substract 30 days from the calendar
    cal.add(Calendar.DATE, -30);
    System.out.println("30 days ago: " + cal.getTime());

}

From source file:Main.java

public static void main(String[] args) {
    Date d1 = new Date();
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, 22);
    Date d2 = cal.getTime();/*from w  w w .  j  a va  2s . co m*/

    Iterator<Date> i = new DateIterator(d1, d2);
    while (i.hasNext()) {
        Date date = i.next();
        System.out.println(date);
    }
}

From source file:Main.java

public static void main(String[] args) {

    Calendar cal = Calendar.getInstance();

    System.out.println("The current date is : " + cal.getTime());

    // add 20 days to the calendar
    cal.add(Calendar.DATE, 20);
    System.out.println("20 days later: " + cal.getTime());

    // subtract 2 months from the calendar
    cal.add(Calendar.MONTH, -2);//from w w  w. j a  v  a 2s.  com
    System.out.println("2 months ago: " + cal.getTime());

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

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.MONTH));
    System.out.println(calendar.get(Calendar.DATE));
    System.out.println(calendar.get(Calendar.HOUR));
    System.out.println(calendar.get(Calendar.MINUTE));
    System.out.println(calendar.get(Calendar.SECOND));
    System.out.println(calendar.get(Calendar.MILLISECOND));
}

From source file:Main.java

public static void main(String[] args) {
    Calendar futureCal = Calendar.getInstance();
    futureCal.set(Calendar.YEAR, 3000);
    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("Is futureCal after now ? : " + futureCal.after(now));
}

From source file:CalendarManipulation.java

public static void main(String s[]) {
    Calendar cal = Calendar.getInstance();
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM);

    System.out.println(df.format(cal.getTime()));

    cal.add(Calendar.DATE, 8);
    System.out.println(df.format(cal.getTime()));
}

From source file:Main.java

public static void main(String[] args) {
    int year = 2009;
    int month = 0; // January
    int date = 1;

    Calendar cal = Calendar.getInstance();
    cal.clear();// ww w  .ja v  a2 s.  c om

    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.DATE, date);

    java.util.Date utilDate = cal.getTime();
    System.out.println(utilDate);
}