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:edu.stanford.muse.email.Filter.java

/**
 * returns date range in the format accepted by filter, e.g., 20130709-20130710. Used only by memory study etc.
 *///from   w ww .j a v a 2  s .c o  m
public static String getDateRangeForLast1Year() {
    Date d = new Date();
    Date d1 = new Date(d.getTime() - (30L * 12 * 24 * 60 * 60 * 1000));
    return dateToString(d1) + "-" + dateToString(d);
}

From source file:edu.stanford.muse.email.Filter.java

/** returns date range in the format accepted by filter, e.g., 20130709-20130710 */
public static String getDateRangeForLastNDays(int n) {
    Date d = new Date();
    Date d1 = new Date(d.getTime() - (((long) n) * 24 * 60 * 60 * 1000));
    return dateToString(d1) + "-" + dateToString(d);
}

From source file:pe.edu.system.jcmr.util.UtilidadesFx.java

public static LocalDate converterDateToLocalDate(Date date) {

    Instant instant = Instant.ofEpochMilli(date.getTime());
    LocalDate localDate = LocalDateTime.ofInstant(instant, ZoneId.systemDefault()).toLocalDate();
    return localDate;
}

From source file:de.yaio.commons.data.DataUtils.java

/** 
 * copy date// w  ww. j a  v a 2  s.  c o  m
 * @param oldDate                date to copy
 * @return                       new Date
 */
public static Date getNewDate(final Date oldDate) {
    return oldDate != null ? new Date(oldDate.getTime()) : null;
}

From source file:com.espertech.esper.client.util.DateTime.java

/**
 * Returns a long-millisecond value from a given string using the default SimpleDateFormat for parsing.
 * @param datestring to parse/*from w w w. jav a  2s.co  m*/
 * @return long msec
 */
public static Long toMillisec(String datestring) {
    Date date = parse(datestring);
    if (date == null) {
        return null;
    }
    return date.getTime();
}

From source file:com.modeln.build.common.tool.CMnCmdLineTool.java

/**
 * Calculate the elapsed time and return a string representing
 * the elapsed time in a human-readable format.
 *
 * @param   start     Starting date/*  w w  w .  j  a  va2  s.  co  m*/
 * @param   end       Ending date
 * @return  Elapsed time text
 */
public static String getElapsedTime(Date start, Date end) {
    long ms = end.getTime() - start.getTime();

    long elapsedMillis = ms % 1000;
    long elapsedSeconds = (ms / 1000) % 60;
    long elapsedMinutes = (ms / (1000 * 60)) % 60;
    long elapsedHours = (ms / (1000 * 60 * 60)) % 24;
    long elapsedDays = ms / (1000 * 60 * 60 * 24);

    StringBuffer elapsedStr = new StringBuffer();
    if (elapsedDays > 0) {
        elapsedStr.append(elapsedDays + "days ");
    }

    if (elapsedHours > 0) {
        elapsedStr.append(elapsedHours + "hr ");
    }

    if (elapsedMinutes > 0) {
        elapsedStr.append(elapsedMinutes + "min ");
    }

    if (elapsedSeconds > 0) {
        elapsedStr.append(elapsedSeconds + "sec ");
    }

    if (elapsedMillis > 0) {
        elapsedStr.append(elapsedMillis + "ms ");
    }

    return elapsedStr.toString();
}

From source file:com.bloatit.web.HtmlTools.java

/**
 * <p>//from   www  . j av  a2  s .  com
 * Clean and formats date and time
 * </p>
 * <p>
 * DateTime is rendered :
 * <li> <code>now</code> if it's been posted less than one second ago</li>
 * <li> <code>x seconds ago</code> if it's been posted less than 1 minute ago
 * </li>
 * <li> <code>Jan 12, 1952  3:30pm</code> otherwise</li>
 * </p>
 * <p>
 * Note, this method will always display date & time. To display only the
 * date, use {@link #formatDate(DateLocale)}
 * </p>
 * 
 * @param date the localized date to render
 * @return the rendered date
 */
public static String formatDateTime(final DateLocale date) {
    final Date currentDate = new Date();

    final long diff = currentDate.getTime() - date.getJavaDate().getTime();

    if (diff < SECOND) {
        return Context.tr("now");
    } else if (diff < MINUTE) {
        return Context.tr("{0} seconds ago", Long.valueOf(diff / SECOND));
    }

    return date.toDateTimeString(FormatStyle.MEDIUM, FormatStyle.SHORT);
}

From source file:com.espertech.esper.client.util.DateTime.java

/**
 * Returns a calendar from a given string using the provided format.
 * @param datestring to parse//from  w w  w.j  a  v a2 s.co m
 * @param format to use for parsing
 * @return calendar
 */
public static Calendar toCalendar(String datestring, String format) {
    Date d = parse(datestring, format);
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(d.getTime());
    return cal;
}

From source file:com.lk.ofo.util.DateUtil.java

public static int dateSubtractOfMin(Date fDate, Date oDate) {
    long between = (oDate.getTime() - fDate.getTime()) / 1000;//1000??
    int min = (int) (between / 60);
    return min;//w  ww.  j a v  a2  s .  c o  m
}

From source file:com.baomidou.framework.common.util.DateUtil.java

/**
 * //from ww w  .j  a  va2 s  .c o  m
 * <br/>
 * 
 *  minuend - subtrahend 
 * 
 * @param subtrahend
 *            ?
 * 
 * @param minuend
 *            ?
 * 
 * @param diffField
 *            ??
 * 
 * @return 
 * 
 */
public static long dateDiff(Date subtrahend, Date minuend, long diffField) {
    long diff = minuend.getTime() - subtrahend.getTime();
    return diff / diffField;
}