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

    // create a calendar    
    Calendar cal = Calendar.getInstance();

    // gets a calendar using the default time zone and locale.
    System.out.print("Date And Time Is: " + cal.getTime());
}

From source file:Main.java

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

    calParis.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
    System.out.println(/*w  ww. java2s . c o  m*/
            "Time in Paris: " + calParis.get(Calendar.HOUR_OF_DAY) + ":" + calParis.get(Calendar.MINUTE));

}

From source file:Main.java

public static void main(String[] args) {

    Calendar cal = Calendar.getInstance();

    // get the current time
    System.out.println("Current time is :" + cal.getTime());

    Date date = new Date();
    cal.setTime(date);//from  w  w  w . ja v a  2  s .co m

    // print the new time
    System.out.println("After setting Time:  " + cal.getTime());
}

From source file:Main.java

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

    int dayOfWeek = now.get(Calendar.DAY_OF_WEEK);
    if (Calendar.SUNDAY == dayOfWeek) {
        System.out.println("SUNDAY");
    }//from   www  .j a  v a  2 s  .  co  m
    if (Calendar.MONDAY == dayOfWeek) {
        System.out.println("MONDAY");
    }
    if (Calendar.TUESDAY == dayOfWeek) {
        System.out.println("TUESDAY");
    }
    if (Calendar.WEDNESDAY == dayOfWeek) {
        System.out.println("WEDNESDAY");
    }
    if (Calendar.THURSDAY == dayOfWeek) {
        System.out.println("THURSDAY");
    }
    if (Calendar.FRIDAY == dayOfWeek) {
        System.out.println("FRIDAY");
    }
    if (Calendar.SATURDAY == dayOfWeek) {
        System.out.println("SATURDAY");
    }
}

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

From source file:Main.java

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

    calNewYork.setTimeZone(TimeZone.getTimeZone("America/New_York"));

    System.out.println("Time in New York: " + calNewYork.get(Calendar.HOUR_OF_DAY) + ":"
            + calNewYork.get(Calendar.MINUTE));

}

From source file:Main.java

public static void main(String[] args) {

    Calendar cal = Calendar.getInstance();

    System.out.println(cal.getTimeZone().getDisplayName());

    TimeZone tz = TimeZone.getTimeZone("GMT");

    // set the time zone with the given time zone value and print it
    cal.setTimeZone(tz);/*from  w  w w. j a va  2  s .c om*/

    System.out.println(cal.getTimeZone().getDisplayName());
}

From source file:Main.java

public static void main(String[] args) {

    Calendar cal = Calendar.getInstance();
    Calendar future = Calendar.getInstance();

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

    future.set(Calendar.YEAR, 2015);
    System.out.println("Year is " + future.get(Calendar.YEAR));

    Date time = future.getTime();
    if (future.after(cal)) {
        System.out.println("Date " + time + " is after current date.");
    }/*from  www .  j  a v  a2  s .c  o  m*/

}

From source file:Main.java

public static void main(String[] args) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, 2007);
    calendar.set(Calendar.DAY_OF_YEAR, 180);

    // See the full information of the calendar object.
    System.out.println(calendar.getTime().toString());

    // Get the weekday and print it
    int weekday = calendar.get(Calendar.DAY_OF_WEEK);
    System.out.println("Weekday: " + weekday);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    int year = 2004;
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, year);
}