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[] argv) throws Exception {
    Formatter fmt = new Formatter();
    Calendar cal = Calendar.getInstance();

    fmt.format("Time using 12-hour clock: %tr\n", cal);
    System.out.println(fmt);// w ww .  j  a  v  a 2 s .  c  o m

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Formatter fmt = new Formatter();
    Calendar cal = Calendar.getInstance();

    fmt.format("Long date format: ");
    fmt.format("%tA %1$tB %1$td, %1$tY\n", cal);
    System.out.println(fmt);/* w  w  w .jav a 2 s .  c  o m*/
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Calendar local = Calendar.getInstance();
    Calendar japanCal = new GregorianCalendar(TimeZone.getTimeZone("Japan"));
    japanCal.setTimeInMillis(local.getTimeInMillis());

    int hour = japanCal.get(Calendar.HOUR); // 3
    int minutes = japanCal.get(Calendar.MINUTE); // 0
    int seconds = japanCal.get(Calendar.SECOND); // 0
    boolean am = japanCal.get(Calendar.AM_PM) == Calendar.AM; // true
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Formatter fmt = new Formatter();
    Calendar cal = Calendar.getInstance();

    // Display 12-hour time format.
    fmt.format("Time using 12-hour clock: %tr\n", cal);
    System.out.println(fmt);//from w w w .  j  ava  2 s  .c o  m

}

From source file:MainClass.java

public static void main(String[] args) throws ParseException {

    Calendar currenttime = Calendar.getInstance();
    Date sqldate = new Date((currenttime.getTime()).getTime());

}

From source file:MainClass.java

public static void main(String args[]) {
    Calendar cal = Calendar.getInstance();
    Date now = new Date();
    cal.setTime(now);//  w w  w.  j a v  a2s  .c  om
    int dayofweek = cal.get(Calendar.DAY_OF_WEEK);
    if (dayofweek == Calendar.SUNDAY)
        System.out.println("SUNDAY");
    if (dayofweek == Calendar.MONDAY)
        System.out.println("MONDAY");
    if (dayofweek == Calendar.TUESDAY)
        System.out.println("TUESDAY");
    if (dayofweek == Calendar.WEDNESDAY)
        System.out.println("WEDNESDAY");
    if (dayofweek == Calendar.THURSDAY)
        System.out.println("THURSDAY");
    if (dayofweek == Calendar.FRIDAY)
        System.out.println("FRIDAY");
    if (dayofweek == Calendar.SATURDAY) {
        System.out.println("SATURDAY");
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Formatter fmt = new Formatter();
    Calendar cal = Calendar.getInstance();

    fmt.format("Time and date in lowercase: %tc\n", cal);
    fmt.format("Time and date in uppercase: %Tc\n", cal);

    System.out.println(fmt);//from  ww w.  ja v a2s  .  c o  m
}

From source file:Main.java

public static void main(String[] args) {
    Calendar localTime = Calendar.getInstance();
    localTime.set(Calendar.HOUR, 17);
    localTime.set(Calendar.MINUTE, 15);
    localTime.set(Calendar.SECOND, 20);

    int hour = localTime.get(Calendar.HOUR);
    int minute = localTime.get(Calendar.MINUTE);
    int second = localTime.get(Calendar.SECOND);

    System.out.printf("Local time  : %02d:%02d:%02d\n", hour, minute, second);

    Calendar germanyTime = new GregorianCalendar(TimeZone.getTimeZone("Germany"));
    germanyTime.setTimeInMillis(localTime.getTimeInMillis());
    hour = germanyTime.get(Calendar.HOUR);
    minute = germanyTime.get(Calendar.MINUTE);
    second = germanyTime.get(Calendar.SECOND);

    System.out.printf("Germany time: %02d:%02d:%02d\n", hour, minute, second);
}

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();//from  w  w  w .  ja v  a 2s . co  m

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

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();/* www. j ava 2s  .c o m*/

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

    java.sql.Date sqlDate = new java.sql.Date(cal.getTimeInMillis());
    System.out.println(sqlDate);
}