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:com.oa.product.action.MyDateUtils.java

/**
 * ?/*from   ww w  . j  a v a2  s  . c o m*/
 * 
 * @param date
 * @return
 */
public static long distanceDays(Date date1, Date date2) {
    long t = date2.getTime() - date1.getTime();
    return t / (24 * 60 * 60 * 1000);
}

From source file:Main.java

public static String string2Timezone(String srcFormater, String srcDateTime, String dstFormater,
        String dstTimeZoneId) {//from   w w w .j a  v  a 2 s.co m
    if (srcFormater == null || "".equals(srcFormater))
        return null;
    if (srcDateTime == null || "".equals(srcDateTime))
        return null;
    if (dstFormater == null || "".equals(dstFormater))
        return null;
    if (dstTimeZoneId == null || "".equals(dstTimeZoneId))
        return null;
    SimpleDateFormat sdf = new SimpleDateFormat(srcFormater);
    try {
        int diffTime = getDiffTimeZoneRawOffset(dstTimeZoneId);
        Date d = sdf.parse(srcDateTime);
        long nowTime = d.getTime();
        long newNowTime = nowTime - diffTime;
        d = new Date(newNowTime);
        return date2String(dstFormater, d);
    } catch (ParseException e) {
        return null;
    } finally {
        sdf = null;
    }
}

From source file:Main.java

public static String string2Timezone(String srcFormater, String srcDateTime, String dstFormater,
        String srcTimeZoneId, String dstTimeZoneId) {
    if (srcFormater == null || "".equals(srcFormater))
        return null;
    if (srcDateTime == null || "".equals(srcDateTime))
        return null;
    if (dstFormater == null || "".equals(dstFormater))
        return null;
    if (dstTimeZoneId == null || "".equals(dstTimeZoneId))
        return null;
    SimpleDateFormat sdf = new SimpleDateFormat(srcFormater);
    try {//from   w  w w. ja  v  a2s. co m
        int diffTime = getDiffTimeZoneRawOffset(srcTimeZoneId, dstTimeZoneId);
        Date d = sdf.parse(srcDateTime);
        long nowTime = d.getTime();
        long newNowTime = nowTime - diffTime;
        d = new Date(newNowTime);
        return date2String(dstFormater, d);
    } catch (ParseException e) {
        return null;
    } finally {
        sdf = null;
    }
}

From source file:net.duckling.ddl.web.agent.util.AuthUtil.java

private static boolean notExpired(Date d) {
    long now = System.currentTimeMillis();
    long dd = d.getTime();
    //??30// w  ww  . j a va 2s. c  o m
    if (Math.abs((now - dd)) < (1000 * 60 * 30)) {
        return true;
    }
    return false;
}

From source file:ee.ria.xroad.asyncdb.AsyncLogWriter.java

private static String dateToSecondsString(Date date) {
    return Long.toString(TimeUnit.MILLISECONDS.toSeconds(date.getTime()));
}

From source file:org.opensprout.osaf.data.hibernate.CriteriaUtils.java

public static void conditionalBetweenTimes(Criteria c, String propertyName, Date from, Date to) {
    if (from != null && to != null)
        c.add(Expression.between(propertyName, new java.sql.Date(from.getTime()),
                new java.sql.Date(DateUtils.getLastDateTimeOf(to).getTime())));
}

From source file:Main.java

/**
 * Wrapper for SimpleDateFormat("yyyyMMddHHmmss").
 * ie. "20140531195908"//from   w w  w.j  a  v a2 s. c  om
 *
 * @param date
 * @return
 */
public static String getFormattedDate(Date date) {
    try {
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyyMMddHHmmss");
        return sdf.format(date.getTime());
    } catch (Exception e) {
    }
    return "" + date.getTime();
}

From source file:com.fluke.application.IEODReader.java

static Timestamp getTimestamp(String date, String time) {
    String year = date.substring(0, 4);
    String month = date.substring(4, 6);
    String day = date.substring(6, 8);
    String timeParts[] = time.split(":");

    Date givenDate = Util.getIEODDate(day + "-" + month + "-" + year + "," + timeParts[0] + ":" + timeParts[1]);
    return new Timestamp(givenDate.getTime());
}

From source file:Main.java

public static long getStringToDate(String time, String format) {
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    Date date = new Date();
    try {/*from  w  w  w .  j av  a 2  s .com*/
        date = sdf.parse(time);
    } catch (ParseException e) {
        e.printStackTrace();
    }

    return date.getTime();
}

From source file:org.killbill.billing.plugin.dao.PluginDao.java

protected static Timestamp toTimestamp(@Nullable final Date date) {
    return date == null ? null : new Timestamp(date.getTime());
}