Example usage for java.util Calendar getTime

List of usage examples for java.util Calendar getTime

Introduction

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

Prototype

public final Date getTime() 

Source Link

Document

Returns a Date object representing this Calendar's time value (millisecond offset from the Epoch").

Usage

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);/*from   w ww.ja v  a  2s.  co m*/
    System.out.println(df.format(cal.getTime()));
}

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.HOUR, -4);// w  ww.  ja v a2s  .  co  m
    System.out.println(df.format(cal.getTime()));
}

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.AM_PM, 1);/*from  ww  w.j  a  v  a 2  s .com*/
    System.out.println(df.format(cal.getTime()));
}

From source file:Easter.java

/** Main program, when used as a standalone application */
public static void main(String[] argv) {

    if (argv.length == 0) {
        int thisYear = new GregorianCalendar().get(Calendar.YEAR);
        Calendar c = Easter.findHolyDay(thisYear);
        System.out.println(c.getTime());
    } else/*from ww w.  j ava  2s. co  m*/
        for (int i = 0; i < argv.length; i++) {
            int year = 0;
            try {
                year = Integer.parseInt(argv[i]);
                System.out.println(Easter.findHolyDay(year).getTime());
            } catch (IllegalArgumentException e) {
                System.err.println("Year " + argv[i] + " invalid (" + e.getMessage() + ").");
            }
        }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Calendar calendar = new GregorianCalendar();
    calendar.set(Calendar.HOUR_OF_DAY, 13); // 1pm

    SpinnerDateModel dateModel = new SpinnerDateModel(calendar.getTime(), null, null, Calendar.HOUR_OF_DAY);
    JSpinner spinner = new JSpinner(dateModel);

    JFormattedTextField tf = ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField();
    DefaultFormatterFactory factory = (DefaultFormatterFactory) tf.getFormatterFactory();
    DateFormatter formatter = (DateFormatter) factory.getDefaultFormatter();

    // Change the date format to only show the hours
    formatter.setFormat(new SimpleDateFormat("hh:00 a"));
    //formatter.setFormat(new SimpleDateFormat("HH:00 a"));
}

From source file:Main.java

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

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

    int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);

    System.out.println("Calendar day of month: " + dayOfMonth);

    int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);

    System.out.println("Calendar day of week: " + dayOfWeek);
}

From source file:Today.java

public static void main(String[] args) {
    Calendar cal = Calendar.getInstance();
    cal.set(HOUR_OF_DAY, 0);//from   www.  ja v a 2s.com
    cal.set(MINUTE, 0);
    cal.set(SECOND, 0);
    cal.set(MILLISECOND, 0);
    System.out.println(cal.getTime());
}

From source file:JapaneseCalendar.java

public static void main(String[] args) {
    Locale japanese = new Locale("ja", "JP", "JP");

    Calendar cal = Calendar.getInstance(japanese);
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, japanese);
    String str = df.format(cal.getTime());

    JOptionPane.showMessageDialog(null, str);
}

From source file:Main.java

public static void main(String... args) {
    Calendar calendar = GregorianCalendar.getInstance();
    calendar.set(YEAR, 2015);//  w ww.j ava2 s.c o  m
    calendar.set(MONTH, MARCH);
    calendar.set(DAY_OF_MONTH, 1);
    System.out.println(calendar.getTime());
    calendar.add(DAY_OF_MONTH, -1);
    System.out.println(calendar.getTime());

}

From source file:MainClass.java

public static void main(String argv[]) throws Exception {
    Calendar cc1 = Calendar.getInstance();
    Calendar cc2 = Calendar.getInstance();
    cc1.add(Calendar.DAY_OF_MONTH, 10);

    DateDiff(cc1.getTime(), cc2.getTime());

    java.util.Date d1 = makeDate("10/10/2000");
    java.util.Date d2 = makeDate("10/18/2000");
    DateDiff(d1, d2);//w ww.  ja  v  a  2  s  .c om

    java.util.Date d3 = makeDate("1/1/2000");
    java.util.Date d4 = makeDate("12/31/2000");
    int diff34 = diff(d3, d4);
    System.out.println("diff34=" + diff34);
}