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

/**
 * calculate difference form two dates Note: both dates are in same format.
 *
 * @param mDate1 date 1//from  w ww.ja v a2s  .c  om
 * @param mDate2 date 2
 * @return date difference in long
 */
public static long calculateDays(Date mDate1, Date mDate2) {
    return Math.abs((mDate1.getTime() - mDate2.getTime()) / (24 * 60 * 60 * 1000) + 1);
}

From source file:Main.java

public static long startOfTodDay() {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    Date date = calendar.getTime();
    return date.getTime();
}

From source file:Main.java

public static Date plusDays(Date date, int days) {
    return new Date(date.getTime() + days * 24 * 3600 * 1000);
}

From source file:Main.java

public static long endOfThisMonth() {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.DAY_OF_MONTH, 1);
    cal.set(Calendar.HOUR_OF_DAY, 23);
    cal.set(Calendar.MINUTE, 59);
    cal.set(Calendar.SECOND, 59);
    cal.set(Calendar.MILLISECOND, 999);
    cal.add(Calendar.MONTH, 1);/*from  ww w.j  av  a  2 s . co m*/
    cal.add(Calendar.DATE, -1);
    Date date = cal.getTime();
    return date.getTime();
}

From source file:Main.java

public static Timestamp dateToSQLTimestamp(java.util.Date d) {

    return d != null ? new Timestamp(d.getTime()) : null;
}

From source file:Main.java

public static long getMs(String str, String format) {
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    try {/*  ww w .  j a  v  a  2 s.co m*/
        Date date = sdf.parse(str);
        return date.getTime();
    } catch (ParseException e) {
        e.printStackTrace();
        return 0;
    }
}

From source file:Main.java

private static int getAge(Date lastUpdate) {
    return (int) ((new Date().getTime() - lastUpdate.getTime()) / 1000);
}

From source file:Main.java

public static Long persistDate(Date date) {
    if (date != null) {
        return date.getTime();
    }// w w  w  .  j a va2  s . c om
    return null;
}

From source file:Main.java

public static float getHourDiff(Date date1, Date date2) {
    return getHourDiff(date1.getTime(), date2.getTime());
}

From source file:Main.java

public static long dateStrToLong(String pattern, String strDate) {
    long date = 0;
    SimpleDateFormat sdf = new SimpleDateFormat(pattern);
    try {/*from w  ww. j av a  2s .c o  m*/
        Date t = sdf.parse(strDate);
        date = t.getTime();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return date;
}