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

private static long getDaysBetweenDates(Date d2) {
    return TimeUnit.MILLISECONDS.toDays(System.currentTimeMillis() - d2.getTime());
}

From source file:Main.java

public static String getFormat3339ByDate(Date date, boolean isallDay) {
    Time time = new Time();
    time.set(date.getTime());
    return time.format3339(isallDay);
}

From source file:Main.java

public static String getPreTime(String sj1, String jj) {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String mydate1 = "";
    try {//  w  w  w.  j  ava  2s.  c om
        Date date1 = format.parse(sj1);
        long Time = (date1.getTime() / 1000) + Integer.parseInt(jj) * 60;
        date1.setTime(Time * 1000);
        mydate1 = format.format(date1);
    } catch (Exception e) {
    }
    return mydate1;
}

From source file:Main.java

public static long getActiveTimelong(String result) {
    try {/*ww  w. ja  va2  s  .c  om*/
        Date parse = yearFormat.parse(result);
        return parse.getTime();
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return System.currentTimeMillis();
}

From source file:Main.java

public static void setHttpResponseDate(String date) {
    try {/*from   w  w  w.  j  a  v  a2s  . c  o  m*/
        DateFormat fmt = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);

        Date d = fmt.parse(date.trim());

        if (d.getTime() < RELEASE_ZERO_TIMESTAMP)
            return;

        TIME_CALIBRATOR = d.getTime() - System.currentTimeMillis();

    } catch (Exception e) {
        // just ignore
    } catch (Error error) {
        // just ignore
    }
}

From source file:Main.java

/**
 * Parses a date string formatted in the format "yyyy-MM-dd HH:mm:ss Z"
 * @param dateString String date representation
 * @return Time in milliseconds since epoch
 * @throws ParseException if the date string could not be parsed e.g. because of different format
 *//*from   ww  w  .  java  2s.  c  om*/
public static long parseDate(String dateString) throws ParseException {
    Date date = TIME_FORMATTER.parse(dateString);
    return date.getTime();
}

From source file:Main.java

public static String StandardFormatStr(String str) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    try {//from  w  w  w.j  a  v  a2s .  c  o  m
        Date d = sdf.parse(str);
        long timeStamp = d.getTime();

        long curTime = System.currentTimeMillis() / (long) 1000;
        long time = curTime - timeStamp / 1000;
        return time / 60 + "";
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static int getDateDiff(Date dateOne, Date dateTwo) {
    long timeOne = dateOne.getTime();
    long timeTwo = dateTwo.getTime();
    long oneDay = 1000 * 60 * 60 * 24;
    long delta = (timeTwo - timeOne) / oneDay;

    if (delta > 0) {
        return (int) delta;
    } else {/*from   w w  w  . ja va2 s . c  o  m*/
        delta *= -1;
        return (int) delta;
    }
}

From source file:DateUtil.java

public static String getTimeDistance(Date from) {
    long minDist = (System.currentTimeMillis() - from.getTime()) / 60000;
    if (minDist <= 0) {
        return (System.currentTimeMillis() - from.getTime()) / 1000 + " seconds";
    } else if (minDist >= 60) {
        return minDist / 60 + " hours";
    } else {/*from  ww  w .ja  v a  2  s. c o m*/
        return minDist + " minutes";
    }
}

From source file:Main.java

public static String getSeconds2() {

    java.util.Date date1 = new java.util.Date();
    Timestamp stamp2 = new Timestamp(date1.getTime());
    return stamp2.toString();
}