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 Date dateAddDays(Date date, int days) {

    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/*from w ww.j  a  v  a  2  s .  c  o  m*/
    cal.add(Calendar.DAY_OF_YEAR, days);
    return cal.getTime();
}

From source file:Main.java

public static boolean isInFuture(int day, int month, int year) {
    Calendar c = Calendar.getInstance();

    c.set(year, month - 1, day);//from w ww  .  ja  v  a2s .  c  om

    Date futureDate = c.getTime();

    return (futureDate.getTime() > new Date().getTime());
}

From source file:Main.java

public static String getTimeString(Calendar time) {
    SimpleDateFormat format = new SimpleDateFormat("h:mm a", Locale.getDefault());
    return format.format(time.getTime());
}

From source file:Main.java

public static Date add(Date date, int amount, int field) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);//  w w  w  .j a v a  2 s .c o  m
    calendar.add(field, amount);
    return calendar.getTime();
}

From source file:Main.java

public static Date addHours(Date date, int hours) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/*  w w  w.  jav a  2  s . c  om*/
    cal.add(Calendar.HOUR_OF_DAY, hours);
    return cal.getTime();
}

From source file:Main.java

public static Date addDays(Date date, int days) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/*from   w  ww.  j  av  a2s  .  co  m*/
    cal.add(Calendar.DAY_OF_MONTH, days);
    return cal.getTime();
}

From source file:Main.java

public static Date getFirstDate(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);/*from   w w  w  .java2 s .  c  o m*/
    calendar.set(Calendar.DATE, 1);
    return calendar.getTime();
}

From source file:Main.java

public static String getTimeStringByCalendar(Calendar calendar) {
    SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_TIME);
    final String timeString = sdf.format(calendar.getTime()) + "00";
    return timeString;
}

From source file:Main.java

public static String GetFormatedDateForQuotedPrice(long milliseconds) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(milliseconds);/*from   w  w  w  .  ja v a 2 s  .  c  om*/
    return GetFormatedDateForQuotedPrice(cal.getTime());
}

From source file:Main.java

/**
 * This method adds days to a date/*from  w w  w  .  ja  v a2 s . c  o m*/
 *
 * @param date the date.
 * @param days the number of days to add.
 */
public static Date getDateAfterAddition(Date date, int days) {
    Calendar cal = Calendar.getInstance();

    cal.setTime(date);
    cal.add(Calendar.DATE, days);

    return cal.getTime();
}