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 long strToDate(String strDate) {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    ParsePosition pos = new ParsePosition(0);
    Date strtodate = formatter.parse(strDate, pos);
    return strtodate.getTime();
}

From source file:DemoPreparedStatementSetTimeAndTimestamp.java

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

From source file:Main.java

public static long getTimeMilliSec(String timeStamp) {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    try {/*from   ww  w  . jav  a2s .  c  o m*/
        Date date = format.parse(timeStamp);
        return date.getTime();
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return 0;
}

From source file:Main.java

public static long getLongDate(String date) {
    try {//from   w  ww . j  av  a 2s .c om
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.getDefault());
        sdf.setTimeZone(TimeZone.getDefault());
        Date d = sdf.parse(date);
        return d.getTime();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return 0;
}

From source file:Main.java

/**
 * Get a diff between two dates//from  w ww  .  j a  v  a2  s. c  o m
 * @param date1 the older date
 * @param date2 the newer date
 * @param timeUnit the unit in which you want the diff
 * @return the diff value, in the provided unit
 */
public static long getDateDiff(Date date1, Date date2, TimeUnit timeUnit) {
    long diffInMillis = date2.getTime() - date1.getTime();
    return timeUnit.convert(diffInMillis, TimeUnit.MILLISECONDS);
}

From source file:Main.java

public static XMLGregorianCalendar date2XMLGregorian(Date date) {
    return long2XMLGregorian(date.getTime());
}

From source file:Main.java

public static long getTimeInLong(String timeString) throws ParseException {
    SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss.SS");
    String base = "00:00:00.00";
    Date baseTime = format.parse(base);
    Date targetTime = format.parse(timeString);
    return targetTime.getTime() - baseTime.getTime();
}

From source file:Main.java

public static long getTime(String dateString) {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    try {// www. j  a  v  a  2s. co m
        Date date = formatter.parse(dateString);
        return date.getTime();
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return SystemClock.elapsedRealtime();
}

From source file:Main.java

/**
 * Get the difference between 2 date/time values down to millisecond
 * @param startDate/*w  w  w .ja  v  a 2  s .  c  o m*/
 * @param endDate
 * @param timeUnit
 * @return long - difference between dates based in timeUnit
 */
public static long calcTimeDifference(Date startDate, Date endDate, TimeUnit timeUnit) {

    long diffInMilliSec = endDate.getTime() - startDate.getTime();
    return timeUnit.convert(diffInMilliSec, timeUnit);
}

From source file:Main.java

public static float calculateTimeDifferenceFrom(Date startTime) {
    long timeDifferenceLong = (new Date()).getTime() - startTime.getTime();
    return (float) timeDifferenceLong / 1000;
}