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

public static int daysBetween(Date date1, Date date2) {
    long timespan = date2.getTime() - date1.getTime();
    return (int) TimeUnit.DAYS.convert(timespan, TimeUnit.MILLISECONDS);
}

From source file:Main.java

public static Long getDateTime() {
    Date date = new Date();
    return -1 * date.getTime();
}

From source file:Main.java

/**
 * The number of days from today until the date passed in.
 *
 * @param date The date to count days until.
 * @return The number of days until the date.
 *///  w  ww.j  a va2 s. c o m
public static long getNumDaysUntilDate(Date date) {
    long msDiff = date.getTime() - Calendar.getInstance().getTimeInMillis();
    return TimeUnit.MILLISECONDS.toDays(msDiff);
}

From source file:Main.java

/**
 *  This method is used to find the no of minutes between dates
 * @param dateEarly/*from   www .ja va2s.c om*/
 * @param dateLater
 * @return
 */
public static long calculateMinutes(Date dateEarly, Date dateLater) {
    return (dateLater.getTime() - dateEarly.getTime()) / 1000 / 60;
}

From source file:Main.java

public static int betweenYear(Date from, Date to) {
    long duration = from.getTime() - to.getTime();
    return (int) (duration / (1000 * 60 * 60 * 24 * 356));
}

From source file:Main.java

public static int betweenHour(Date from, Date to) {
    long duration = from.getTime() - to.getTime();
    return (int) (duration / (1000 * 60 * 60));
}

From source file:Main.java

public static int betweenDay(Date from, Date to) {
    long duration = from.getTime() - to.getTime();
    return (int) (duration / (1000 * 60 * 60 * 24));
}

From source file:Main.java

public static long date2long(int hour, int minute, int second) {
    Calendar c = Calendar.getInstance();
    c.set(Calendar.HOUR_OF_DAY, 18);
    c.set(Calendar.MINUTE, 0);//from  w ww  . j a  v  a2 s .c  o m
    c.set(Calendar.SECOND, 0);
    Date d = c.getTime();
    return d.getTime();
}

From source file:Main.java

public static int compareTo(Date remindAt, Calendar now) {
    if (remindAt.getTime() == now.getTimeInMillis())
        return 0;
    return remindAt.getTime() - now.getTimeInMillis() < 0 ? -1 : 1;
}

From source file:Main.java

public static int betweenMin(Date from, Date to) {
    long duration = from.getTime() - to.getTime();
    return (int) (duration / (1000 * 60));
}