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

public static void main(String[] args) {

    Calendar cal = new GregorianCalendar(2013, 05, 20);

    System.out.println("Past calendar : " + cal.getTime());

    // create a clone of first cal
    Calendar cal2 = (Calendar) cal.clone();

    System.out.println("Cloned calendar : " + cal2.getTime());
}

From source file:Main.java

public static void main(String args[]) {
    int days = 1;
    int month = 1;
    int year = 2001;
    SimpleDateFormat sdf = new SimpleDateFormat("E dd-MM-yyyy G");
    StringBuffer buf = new StringBuffer();
    Calendar cal = new GregorianCalendar();
    cal.set(year, month - 1, days);//w w  w .  jav a2 s. c  o m
    sdf.format(cal.getTime(), buf, new FieldPosition(10));
    System.out.println(buf.toString());
}

From source file:TimeTrial.java

public static void main(String[] args) {

    StopWatch stWatch = new StopWatch();

    // Start StopWatch
    stWatch.start();/*from   w  w w . j ava 2 s  . c om*/

    // Get iterator for all days in a week starting Monday
    Iterator itr = DateUtils.iterator(new Date(), DateUtils.RANGE_WEEK_MONDAY);

    while (itr.hasNext()) {
        Calendar gCal = (Calendar) itr.next();
        System.out.println(gCal.getTime());
    }

    // Stop StopWatch
    stWatch.stop();
    System.out.println("Time Taken >>" + stWatch.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  .  j a  v  a2s  .co  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) {
    Date today = new Date();

    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, 1);
    Date tomorrow = calendar.getTime();

    if (tomorrow.after(today)) {
        System.out.println(tomorrow + " is after " + today);
    }//w ww.  ja  v  a2  s.  c o  m
}

From source file:Main.java

public static void main(String[] args) {

    Calendar now = Calendar.getInstance();
    Date nowDate = now.getTime();

    long twoHoursByMillis = 2 * HOUR;
    long thirtyMinutesByMillis = 30 * MINUTE;

    Date twoHoursAndThirtyMinutesFromNow = new Date(twoHoursByMillis + thirtyMinutesByMillis);
    System.out.println(String.format("now %s and later %s", nowDate, twoHoursAndThirtyMinutesFromNow));

    long ms = 10304004543l;
    StringBuilder text = new StringBuilder("");
    if (ms > DAY) {
        text.append(ms / DAY).append(" days ");
        ms %= DAY;/*from w ww  . j a va2s  . com*/
    }
    if (ms > HOUR) {
        text.append(ms / HOUR).append(" hours ");
        ms %= HOUR;
    }
    if (ms > MINUTE) {
        text.append(ms / MINUTE).append(" minutes ");
        ms %= MINUTE;
    }
    if (ms > SECOND) {
        text.append(ms / SECOND).append(" seconds ");
        ms %= SECOND;
    }
    text.append(ms + " ms");
    System.out.println(text.toString());
}

From source file:Main.java

public static void main(String[] args) {
    Date today = new Date();

    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, -1);
    Date yesterday = calendar.getTime();

    if (yesterday.before(today)) {
        System.out.println(yesterday + " is before " + today);
    }/*from ww  w .  jav  a2 s.  c  o m*/
}

From source file:Main.java

public static void main(String[] args) {
    Calendar cal = Calendar.getInstance();
    System.out.println("Calendar:" + cal.toString());
    Date d = cal.getTime();
    SimpleDateFormat sdf = new SimpleDateFormat("DD/MM/yyyy HH:mm:ss");
    System.out.println(sdf.format(d));
    SimpleDateFormat sdfNew = new SimpleDateFormat("HH:mm:ss");
    System.out.println(sdfNew.format(d));
}

From source file:Main.java

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

    Calendar cal = Calendar.getInstance();

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

}

From source file:Main.java

/** Typical main method ("main program") declaration */
public static void main(String[] av) {

    Locale l1 = new Locale("en", "US"), l2 = new Locale("es", "ES");

    // Create a Date object for May 5, 1986
    Calendar c = Calendar.getInstance();
    c.set(1986, 04, 05); // May 5, 1986
    Date d1 = c.getTime();

    // Create a Date object for today.
    Date d2 = new Date(); // today

    DateFormat df_us = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, l1),
            df_sp = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, l2);
    System.out.println("Date d1 for US is " + df_us.format(d1));
    System.out.println("Date d1 for Spain is " + df_sp.format(d1));
    System.out.println("Date d2 is " + df_us.format(d2));
}