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:MainClass.java

public static void main(String args[]) {
    Formatter fmt = new Formatter();

    // ./*w w  w .ja v  a2s. c om*/
    fmt = new Formatter();
    fmt.format("%tc", Calendar.getInstance());
    System.out.println(fmt);

}

From source file:Test.java

public static void main(String[] args) {
    Locale locale = Locale.getDefault();
    Calendar calendar = Calendar.getInstance();
    calendar.setWeekDate(2012, 16, 3);/*from   w  w  w  .  j  a  v a 2 s  .c om*/

    System.out.println(
            DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(calendar.getTime()));
    System.out.println("" + locale.getDisplayLanguage());

    Locale.setDefault(Locale.Category.FORMAT, Locale.JAPANESE);
    Locale.setDefault(Locale.Category.DISPLAY, Locale.GERMAN);

    System.out.println(
            DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(calendar.getTime()));
    System.out.println("" + locale.getDisplayLanguage());

}

From source file:MainClass.java

public static void main(String args[]) {
    Formatter fmt = new Formatter();

    // Display standard 12-hour time format.
    fmt.format("%tr", Calendar.getInstance());
    System.out.println(fmt);//from  w w  w . j av  a  2  s .  c om

}

From source file:MainClass.java

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

    fmt.format("Today is day %te of %<tB, %<tY", cal);
    System.out.println(fmt);//from  www  .ja v  a  2  s . co m
}

From source file:Main.java

public static void main(String args[]) {
    String months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };

    Calendar calendar = Calendar.getInstance();

    // Set the time and date information and display it.
    calendar.set(Calendar.HOUR, 10);
    calendar.set(Calendar.MINUTE, 29);
    calendar.set(Calendar.SECOND, 22);

    System.out.print("Updated time: ");
    System.out.print(calendar.get(Calendar.HOUR) + ":");
    System.out.print(calendar.get(Calendar.MINUTE) + ":");
    System.out.println(calendar.get(Calendar.SECOND));
}

From source file:Main.java

public static void main(String args[]) {
    String DATE_FORMAT = "yyyyMMdd";
    SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
    Calendar c1 = Calendar.getInstance(); // today
    System.out.println("Today is " + sdf.format(c1.getTime()));
}

From source file:Test.java

public static void main(String[] args) {
    Calendar calendar = Calendar.getInstance();
    calendar.setWeekDate(2012, 16, 3);//  ww  w  . j a  v  a2 s  . co m

    Builder builder = new Builder();
    builder.setLanguage("hy");
    builder.setScript("Latn");
    builder.setRegion("IT");
    builder.setVariant("arevela");

    Locale locale = builder.build();
    Locale.setDefault(locale);

    System.out.println(
            DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(calendar.getTime()));
    System.out.println("" + locale.getDisplayLanguage());

    builder.setLanguage("zh");
    builder.setScript("Hans");
    builder.setRegion("CN");

    locale = builder.build();
    Locale.setDefault(locale);

    System.out.println(
            DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(calendar.getTime()));
    System.out.println("" + locale.getDisplayLanguage());

}

From source file:DateCalAdd.java

public static void main(String[] av) {
    /** Today's date */
    Calendar now = Calendar.getInstance();

    /* Do "DateFormat" using "simple" format. */
    SimpleDateFormat formatter = new SimpleDateFormat("E yyyy/MM/dd 'at' hh:mm:ss a zzz");
    System.out.println("It is now " + formatter.format(now.getTime()));

    now.add(Calendar.YEAR, -2);//ww w .ja  v a 2s .  c  o m
    System.out.println("Two years ago was " + formatter.format(now.getTime()));
}

From source file:Main.java

public static void main(String[] args) {
    Date date1 = new Date(2009, 01, 10);
    Date date2 = new Date(2015, 07, 01);
    Calendar calendar1 = Calendar.getInstance();
    Calendar calendar2 = Calendar.getInstance();
    calendar1.setTime(date1);/*from  ww w . ja v a  2s.c  o m*/
    calendar2.setTime(date2);
    long milliseconds1 = calendar1.getTimeInMillis();
    long milliseconds2 = calendar2.getTimeInMillis();
    long diff = milliseconds2 - milliseconds1;
    long diffSeconds = diff / 1000;
    long diffMinutes = diff / (60 * 1000);
    long diffHours = diff / (60 * 60 * 1000);
    long diffDays = diff / (24 * 60 * 60 * 1000);
    System.out.println("\nThe Date Different Example");
    System.out.println("Time in milliseconds: " + diff + " milliseconds.");
    System.out.println("Time in seconds: " + diffSeconds + " seconds.");
    System.out.println("Time in minutes: " + diffMinutes + " minutes.");
    System.out.println("Time in hours: " + diffHours + " hours.");
    System.out.println("Time in days: " + diffDays + " days.");
}

From source file:Main.java

public static void main(String[] args) {
    DateFormat df = new SimpleDateFormat("MM/dd/yyyy");

    Date today = Calendar.getInstance().getTime();
    String reportDate = df.format(today);

    System.out.println("Report Date: " + reportDate);
}