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 String getDateDiff(Date date1, Date date2) {
    long diff = date2.getTime() - date1.getTime();
    long diffInSeconds = diff / 1000 % 60;
    long diffInMinutes = diff / (60 * 1000) % 60;
    long diffInHours = diff / (60 * 60 * 1000) % 24;
    long diffInDays = diff / (24 * 60 * 60 * 1000);
    StringBuilder returnString = new StringBuilder();
    if (diffInDays >= 1) {
        returnString.append(diffInDays + " days ");
    }//from  w w  w . j  a va  2 s  .c o  m
    if (diffInHours >= 1) {
        returnString.append(diffInHours + " hours ");
    }
    if (diffInMinutes >= 1) {
        returnString.append(diffInMinutes + " minutes ");
    }
    Log.d("praveen panduru", "timediff is " + returnString.toString());
    return returnString.toString();
}

From source file:Main.java

public static Long convertDateToLong(Date date) {
    if (date != null) {
        return date.getTime();
    }/*from www  . j a va2 s. c  o  m*/
    return null;
}

From source file:Main.java

/**
 * @param time/*  w w  w .  java2s .  co  m*/
 * @param format "MMM dd yyyy HH:mm:ss.SSS zzz"
 * @return
 */
public static long getEpochTime(String time, String format) {
    try {
        SimpleDateFormat df = new SimpleDateFormat(format);
        Date date = df.parse(time);
        return date.getTime() / 1000;
    } catch (Exception e) {
        return 0;
    }
}

From source file:Main.java

public static String getTimeStamp(String str) {
    long stamp = 0;
    SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    try {/*from  w w w . j a v a 2 s  .  c om*/
        Date date = dfs.parse(str);
        stamp = date.getTime();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return stamp + "";
}

From source file:DemoPreparedStatementSetTimeAndTimestamp.java

public static java.sql.Time getCurrentJavaSqlTime() {
    java.util.Date date = new java.util.Date();
    return new java.sql.Time(date.getTime());
}

From source file:Main.java

public static long getDifferenceBetweenTwoDates(Date begin, Date end) {
    long difference = begin.getTime() - end.getTime();
    // seconds/*from   w  w  w  . j a  va2 s  .  c  o m*/
    long seconds = difference / 1000;
    // minutes
    long minutes = seconds / 60;
    // hours
    long hours = minutes / 60;
    // days
    long days = hours / 24;
    return days;
}

From source file:Main.java

public static Date getdatebyDays(int DAYS) {
    Date today = new Date();
    Long Before_Date = (today.getTime() / 1000) - 60 * 60 * 24 * DAYS;
    today.setTime(Before_Date * 1000);
    return today;
}

From source file:Main.java

public static String getDatebyDays(int DAYS) {
    Date today = new Date();
    Long Before_Date = (today.getTime() / 1000) - 60 * 60 * 24 * DAYS;
    today.setTime(Before_Date * 1000);
    return format.format(today);
}

From source file:Main.java

public static long dateStrToLong(String strDate) {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    ParsePosition pos = new ParsePosition(0);
    Date strtodate = formatter.parse(strDate, pos);
    return strtodate.getTime();
}

From source file:Main.java

public static boolean isTheDay(final Date date, final Date day) {
    return date.getTime() >= dayBegin(day).getTime() && date.getTime() <= dayEnd(day).getTime();
}