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:Main.java

public static long getStartOfWeek(long week) {
    Calendar calendar = getCalendarWithTime(week);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.clear(Calendar.MINUTE);
    calendar.clear(Calendar.SECOND);
    calendar.clear(Calendar.MILLISECOND);

    // get start of this week in milliseconds
    calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek());

    return calendar.getTimeInMillis();
}

From source file:Main.java

public static long timeToMills(String timeString) {
    Calendar c = Calendar.getInstance();
    c.set(Integer.parseInt(timeString.substring(0, 4)), Integer.parseInt(timeString.substring(4, 6)) - 1,
            Integer.parseInt(timeString.substring(6, 8)), Integer.parseInt(timeString.substring(8, 10)),
            Integer.parseInt(timeString.substring(10, 12)), Integer.parseInt(timeString.substring(12, 14)));

    return c.getTimeInMillis();
}

From source file:ConversionUtil.java

/**
 * convert into java.sql.Time (or into java.util.Calendar
 * /*from   w w w.  j a va  2 s .  co m*/
 * @param date
 *          The date containing the time.
 * @param am
 *          Whether this should be am (true) or pm (false)
 * @return
 */
public static Time convertDateToTime(Date date, boolean am) {
    if (date == null) {
        return null;
    }

    Calendar cal = new GregorianCalendar();
    cal.setTime(date);
    int hourOfDay = cal.get(Calendar.HOUR_OF_DAY);

    if (am) {
        // Check to make sure that the hours are indeed am hours
        if (hourOfDay > 11) {
            cal.set(Calendar.HOUR_OF_DAY, hourOfDay - 12);
            date.setTime(cal.getTimeInMillis());
        }
    } else {
        // Check to make sure that the hours are indeed pm hours
        if (cal.get(Calendar.HOUR_OF_DAY) < 11) {
            cal.set(Calendar.HOUR_OF_DAY, hourOfDay + 12);
            date.setTime(cal.getTimeInMillis());
        }
    }
    return new Time(date.getTime());
}

From source file:Main.java

public static Long getToday() {
    Calendar today = Calendar.getInstance();
    today.setTimeZone(TimeZone.getDefault());

    today.set(Calendar.SECOND, 0);
    today.set(Calendar.MINUTE, 0);
    today.set(Calendar.HOUR_OF_DAY, 1);
    today.set(Calendar.MILLISECOND, 0);

    // FOR DEBUG/*w w w .j  a v a 2s  .  c  o  m*/
    //today.set(Calendar.DAY_OF_YEAR, today.get(Calendar.DAY_OF_YEAR) + 1);

    return today.getTimeInMillis();
}

From source file:TimeLib.java

/**
 * Get the timestamp for the given year, month, and, day.
 * @param c a Calendar to use to help compute the result. The state of the
 * Calendar will be overwritten./*from   ww  w. ja v  a  2 s  .  c o m*/
 * @param year the year to look up
 * @param month the month to look up (months start at 0==January)
 * @param day the day to look up
 * @return the timestamp for the given date
 */
public static long getDate(Calendar c, int year, int month, int day) {
    c.clear(Calendar.MILLISECOND);
    c.set(year, month, day, 0, 0, 0);
    return c.getTimeInMillis();
}

From source file:Main.java

/**
 * Add date time with five hours.//  ww w  .  j ava2  s  . c  o  m
 *
 * @param listing     the listing
 * @param currentTime the current time
 * @param isPast      true/false if past time
 */
private static void addDateTimeWithFiveHours(final List<Long> listing, final long currentTime,
        final boolean isPast) {
    final Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(currentTime);
    calendar.add(Calendar.HOUR, isPast ? -3 : 3);
    listing.add(calendar.getTimeInMillis());
}

From source file:Main.java

/**
 * Add date time with six months.//from   ww  w .  j a  v  a  2s  . c  om
 *
 * @param listing     the listing
 * @param currentTime the current time
 * @param isPast      true/false if past time
 */
private static void addDateTimeWithSixMonths(final List<Long> listing, final long currentTime,
        final boolean isPast) {
    final Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(currentTime);
    calendar.add(Calendar.MONTH, isPast ? -6 : 6);
    listing.add(calendar.getTimeInMillis());
}

From source file:Main.java

/**
 * Add date time with nine minutes.//from  w w  w. j a v a  2s .c  o  m
 *
 * @param listing     the listing
 * @param currentTime the current time
 * @param isPast      true/false if past time
 */
private static void addDateTimeWithNineMinutes(final List<Long> listing, final long currentTime,
        final boolean isPast) {
    final Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(currentTime);
    calendar.add(Calendar.MINUTE, isPast ? -9 : 9);
    listing.add(calendar.getTimeInMillis());
}

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

public static void waitFor(long nbHistories, int timeoutMs, EntityManager em) {
    TypedQuery<Long> q = em.createQuery("SELECT COUNT(h) FROM History h", Long.class);

    Calendar start = Calendar.getInstance();
    while (q.getSingleResult() < nbHistories
            && Calendar.getInstance().getTimeInMillis() - start.getTimeInMillis() <= timeoutMs) {
        try {// w  ww .ja v a2s. c om
            Thread.sleep(100);
        } catch (InterruptedException e) {
        }
    }
}

From source file:Main.java

/**
 * Add date time with fifty one minutes.
 *
 * @param listing     the listing/*  w w w .  j av a2 s.c o m*/
 * @param currentTime the current time
 * @param isPast      true/false if past time
 */
private static void addDateTimeWithFiftyOneMinutes(final List<Long> listing, final long currentTime,
        final boolean isPast) {
    final Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(currentTime);
    calendar.add(Calendar.MINUTE, isPast ? -51 : 51);
    listing.add(calendar.getTimeInMillis());
}