Example usage for java.util Calendar getInstance

List of usage examples for java.util Calendar getInstance

Introduction

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

Prototype

public static Calendar getInstance() 

Source Link

Document

Gets a calendar using the default time zone and locale.

Usage

From source file:Main.java

public static void main(String[] args) {

    Calendar cal = Calendar.getInstance();

    // print current first day of the week
    int day = cal.getFirstDayOfWeek();
    System.out.println("Current first day of the week:" + day);

    // set first day of the week as something else
    cal.setFirstDayOfWeek(Calendar.WEDNESDAY);

    // print altered first day of the week
    day = cal.getFirstDayOfWeek();/*from   w w w .j  a  v  a 2  s  . com*/
    ;
    System.out.println("Altered first day of the week:" + day);
}

From source file:Main.java

public static void main(String args[]) {

    Object a[] = { "String 1", "String 2", Calendar.getInstance() };

    System.out.println(String.format("Hi %1$s at %2$s ( %3$tY %3$tm %3$te )", a));
}

From source file:Main.java

public static void main(String[] args) {

    Calendar cal = Calendar.getInstance();

    // display the current date and time
    System.out.println("Current Calendar Date: " + cal.getTime());

    // use clear method to set year as undefined.
    cal.clear(Calendar.YEAR);/*from  w w w  .j av  a 2s . co m*/

    // print the result
    System.out.println("The calendar shows : " + cal.getTime());

    // use clear method to set month as undefined.
    cal.clear(Calendar.MONTH);

    System.out.println("The calendar shows : " + cal.getTime());
}

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);/*  w w  w .  java2s . c  o  m*/
    System.out.println("20 days later: " + cal.getTime());

    // subtract 2 months from the calendar
    cal.add(Calendar.MONTH, -2);
    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:Main.java

public static void main(String[] args) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
}

From source file:Main.java

public static void main(String[] args) {
    Calendar now = Calendar.getInstance();
    TimeZone timeZone = now.getTimeZone();
    System.out.println("Current TimeZone is : " + timeZone.getDisplayName());
}

From source file:DateAddHour.java

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

    // Subtract 2 hour from the current time
    calendar.add(Calendar.HOUR, -2);

    // Add 30 minutes to the calendar time
    calendar.add(Calendar.MINUTE, 30);

    // Add 300 seconds to the calendar time
    calendar.add(Calendar.SECOND, 300);
    System.out.println("Updated  = " + calendar.getTime());
}

From source file:DateAddHour.java

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

    // Substract 2 hour from the current time
    calendar.add(Calendar.HOUR, -2);

    // Add 30 minutes to the calendar time
    calendar.add(Calendar.MINUTE, 30);

    // Add 300 seconds to the calendar time
    calendar.add(Calendar.SECOND, 300);
    System.out.println("Updated  = " + calendar.getTime());
}

From source file:Main.java

public static void main(String[] args) {

    Calendar cal = Calendar.getInstance();

    // display the current calendar
    System.out.println("Month is " + cal.get(Calendar.MONTH));

    // roll month
    cal.roll(Calendar.MONTH, 2);/*from  w  w  w  .j  av a2s  .  co  m*/

    // print result after rolling
    System.out.println("Month is " + cal.get(Calendar.MONTH));

    // roll downwards
    cal.roll(Calendar.MONTH, -4);

    // print result
    System.out.println("Month is " + cal.get(Calendar.MONTH));
}

From source file:Main.java

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

    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, 2000);
    Date d2 = cal.getTime();/*from   ww  w .  j a va 2 s .  c  o m*/

    System.out.println("First Date : " + d1);
    System.out.println("Second Date : " + d2);
    System.out.println("Is second date after first ? : " + d2.after(d1));
}