Example usage for java.util Date getTime

List of usage examples for java.util Date getTime

Introduction

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

Prototype

public long getTime() 

Source Link

Document

Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.

Usage

From source file:Main.java

/**
 * Get Date from Date//from   ww  w  .j  av a  2 s  . co  m
 * @param date Date
 * @return Date generated
 */
public static Date generateDate(Date date) {
    return new Date(date.getTime());
}

From source file:Main.java

public static double calculateAgeInHoursDouble(Date birthTime, Date evalTime) {
    long age = evalTime.getTime() - birthTime.getTime();
    return (double) (age / HOURS_FACTOR);
}

From source file:Main.java

public static int calculateAgeInHoursInt(Date birthTime, Date evalTime) {
    long age = evalTime.getTime() - birthTime.getTime();
    return (int) (age / HOURS_FACTOR);
}

From source file:Main.java

public static long getTimeInMills(String dateStr) throws ParseException {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
    Date date = sdf.parse(dateStr);
    return date.getTime();
}

From source file:Main.java

/**
 * Returns the number of days between the start date (inclusive) and end
 * date (exclusive). The value is rounded off to the floor value and does
 * not take daylight saving time into account.
 *
 * @param startDate the start-date.//from   ww w.  j av a2  s  .  co m
 * @param endDate   the end-date.
 * @return the number of days between the start and end-date.
 */
public static long getDays(Date startDate, Date endDate) {
    return (endDate.getTime() - startDate.getTime()) / MS_PER_DAY;
}

From source file:Main.java

/**
 * @param date1 -past date/*w w  w.j  av a  2  s  .c  om*/
 * @param date2 -future date than date1
 * @return total days between Dates
 */
private static int getDaysBetweenDates(Date date1, Date date2) {
    return (int) ((date2.getTime() - date1.getTime()) / (1000 * 60 * 60 * 24l));
}

From source file:Main.java

public static long diff(Date subtrahend, Date minuend, long diffField) {
    long diff = minuend.getTime() - subtrahend.getTime();
    return diff / diffField;
}

From source file:Main.java

public static String getNextHour(String format, int h) {
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    Date date = new Date();
    date.setTime(date.getTime() + h * 60 * 60 * 1000);
    return sdf.format(date);

}

From source file:Main.java

public static int diffDate(Date fromDay, Date toDay) {

    long from = fromDay.getTime();
    long to = toDay.getTime();
    return (int) TimeUnit.MILLISECONDS.toDays(to - from);
}

From source file:Main.java

public static long TimestampBeforeSec(long sec) {
    java.util.Date Now = new java.util.Date();
    return Now.getTime() - sec;
}