Example usage for java.util Calendar getTimeInMillis

List of usage examples for java.util Calendar getTimeInMillis

Introduction

In this page you can find the example usage for java.util Calendar getTimeInMillis.

Prototype

public long getTimeInMillis() 

Source Link

Document

Returns this Calendar's time value in milliseconds.

Usage

From source file:com.my373.common.util.MyDateUtils.java

/**
 * 2endDate - beginDate/*from   w  w w .jav a2 s.c o  m*/
 * 
 * @param endDate
 * @param beginDate
 * @return
 */
public static int subDate(Date endDate, Date beginDate) {
    Calendar d1 = Calendar.getInstance();
    d1.setTime(endDate);
    d1 = setTimeToMidnight(d1);

    Calendar d2 = Calendar.getInstance();
    d2.setTime(beginDate);
    d2 = setTimeToMidnight(d2);

    // 1000 * 60 * 60 * 24 = 86400000,??
    return (int) ((d1.getTimeInMillis() - d2.getTimeInMillis()) / 86400000);
}

From source file:com.enioka.jqm.test.helpers.TestHelpers.java

public static void waitForRunning(long nbJobInstances, int timeoutMs, EntityManager em) {
    TypedQuery<Long> q = em.createQuery("SELECT COUNT(ji) FROM JobInstance ji WHERE ji.state = 'RUNNING'",
            Long.class);

    Calendar start = Calendar.getInstance();
    while (q.getSingleResult() < nbJobInstances
            && Calendar.getInstance().getTimeInMillis() - start.getTimeInMillis() <= timeoutMs) {
        try {/*from   www  .  j  a  va  2s .  c o m*/
            Thread.sleep(100);
        } catch (InterruptedException e) {
        }
    }
}

From source file:TimeLib.java

/**
 * Get a timestamp for the given hour, minute, and second. The date will
 * be assumed to be January 1, 1970./*from w w  w  .  java2 s .  com*/
 * @param c a Calendar to use to help compute the result. The state of the
 * Calendar will be overwritten.
 * @param hour the hour, on a 24 hour clock
 * @param minute the minute value
 * @param second the seconds value
 * @return the timestamp for the given date
 */
public static long getTime(Calendar c, int hour, int minute, int second) {
    c.clear(Calendar.MILLISECOND);
    c.set(1970, 0, 1, hour, minute, second);
    return c.getTimeInMillis();
}

From source file:com.kongwu.insweb.utils.DateUtils.java

/**
 * Calendar?Timestamp/*from   w ww  . jav  a  2  s . com*/
 *
 * @param c
 * @return
 */
public static Timestamp calendar2Timestamp(Calendar c) {
    return new Timestamp(c.getTimeInMillis());
}

From source file:gemlite.core.common.DateUtil.java

/**
 * //w ww .  j  a  v a  2  s  .c  om
 * @return
 */
public static long today() {
    Calendar c = Calendar.getInstance();
    c.setTime(new Date());
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.HOUR_OF_DAY, 0);
    return c.getTimeInMillis();
}

From source file:MainClass.java

public static Timestamp makeTimestamp(int year, int month, int day, int hour, int minute, int second,
        int millisecond) {
    Calendar cal = new GregorianCalendar();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month - 1);
    cal.set(Calendar.DATE, day);//from   www  . ja v  a 2 s.co  m
    cal.set(Calendar.HOUR_OF_DAY, hour);
    cal.set(Calendar.MINUTE, minute);
    cal.set(Calendar.SECOND, second);
    cal.set(Calendar.MILLISECOND, millisecond);

    // now convert GregorianCalendar object to Timestamp object
    return new Timestamp(cal.getTimeInMillis());
}

From source file:com.maydesk.base.util.PDUtil.java

public static int getDaysDifference(Calendar refDate, Date date) {
    long delta = date.getTime() - refDate.getTimeInMillis();
    long deltaDays = (delta) / MILLIS_PER_DAY;
    return (int) deltaDays;
}

From source file:com.gm.machine.util.CommonUtils.java

/**
 * /*  w  ww  . j  a  va2  s. c  o m*/
 *  ?? 
 * 
 * @since 2011-12-1
 * @author qingang
 * @param one
 * @param two
 * @return
 */
public static long getDateTimeBetween(Date one, Date two) {
    Calendar cone = Calendar.getInstance();
    Calendar ctwo = Calendar.getInstance();
    cone.setTime(one);
    ctwo.setTime(two);
    return ((ctwo.getTimeInMillis() - cone.getTimeInMillis()) / 1000 / 60);

}

From source file:com.appeligo.search.entity.Message.java

public static void deleteOldMessages(int days, int maxAttempts) {
    Session session = getSession();/* w  ww .j  a v  a2 s .c  o  m*/
    Query query = session.getNamedQuery("Message.deleteOldMessages");
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.HOUR_OF_DAY, (0 - (days * 24)));
    query.setTimestamp("oldestSent", new Timestamp(cal.getTimeInMillis()));
    query.setInteger("maxAttempts", maxAttempts);
    query.executeUpdate();
}

From source file:com.krayzk9s.imgurholo.tools.ImageUtils.java

public static void updateInfoFont(JSONParcelable imageData, TextView infoText) {
    try {// ww  w . j a v  a  2  s .com
        String albumText = "";
        if (imageData.getJSONObject().has("is_album") && imageData.getJSONObject().getBoolean("is_album"))
            albumText = "[album] ";
        if (!imageData.getJSONObject().getString("section").equals("null"))
            albumText += "/r/" + imageData.getJSONObject().getString("section") + " " + Html.fromHtml("&#8226;")
                    + " ";
        Calendar calendar = Calendar.getInstance();
        long now = calendar.getTimeInMillis();
        infoText.setText(albumText
                + DateUtils.getRelativeTimeSpanString(imageData.getJSONObject().getLong("datetime") * 1000, now,
                        DateUtils.MINUTE_IN_MILLIS)
                + " " + Html.fromHtml("&#8226;") + " ");
    } catch (JSONException e) {
        Log.e("Error!", e.toString());
    }
}