Example usage for java.util Calendar setTimeInMillis

List of usage examples for java.util Calendar setTimeInMillis

Introduction

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

Prototype

public void setTimeInMillis(long millis) 

Source Link

Document

Sets this Calendar's current time from the given long value.

Usage

From source file:Main.java

/**
 * Add date time with nine minutes.//from   w w w  . j  a  v  a2s .co  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:Main.java

/**
 * Add date time with fifty one minutes.
 *
 * @param listing     the listing//www.  j  ava2s.  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());
}

From source file:Main.java

/**
 * Add date time with five hours./*www.  j  av a  2  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 . jav  a  2  s  . c  o m
 *
 * @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 over one year.//w w  w .  ja 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 addDateTimeOverOneYear(final List<Long> listing, final long currentTime,
        final boolean isPast) {
    final Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(currentTime);
    calendar.add(Calendar.MONTH, isPast ? -4 : 4);
    calendar.add(Calendar.YEAR, isPast ? -1 : 1);
    listing.add(calendar.getTimeInMillis());
}

From source file:com.google.orkut.client.api.Util.java

static String getFormattedTimestamp(long timeMillis) {
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(Constants.DateFormatter.UTC));
    cal.setTimeInMillis(timeMillis);
    StringBuilder date = new StringBuilder();
    date.append(cal.get(Calendar.YEAR));
    date.append(Constants.DateFormatter.DATE_SEPARATOR);
    date.append(padSingleDigitNum(cal.get(Calendar.MONTH) + 1));
    date.append(Constants.DateFormatter.DATE_SEPARATOR);
    date.append(padSingleDigitNum(cal.get(Calendar.DATE)));
    date.append(Constants.DateFormatter.DATE_DELIM);
    date.append(padSingleDigitNum(cal.get(Calendar.HOUR)));
    date.append(Constants.DateFormatter.TIME_SEPARATOR);
    date.append(padSingleDigitNum(cal.get(Calendar.MINUTE)));
    date.append(Constants.DateFormatter.TIME_SEPARATOR);
    date.append(padSingleDigitNum(cal.get(Calendar.SECOND)));
    date.append(Constants.DateFormatter.TIME_DELIM);
    return date.toString();
}

From source file:Main.java

/**
 * Add date time with one minute./*  w w  w .  ja v a  2 s .c o m*/
 *
 * @param listing     the listing
 * @param currentTime the current time
 * @param isPast      true/false if past time
 */
private static void addDateTimeWithOneMinute(final List<Long> listing, final long currentTime,
        final boolean isPast) {
    final Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(currentTime);
    if (isPast) {
        calendar.add(Calendar.MINUTE, -1);
    } else {
        calendar.add(Calendar.SECOND, 62);
    }
    listing.add(calendar.getTimeInMillis());
}

From source file:net.firejack.platform.core.utils.DateUtils.java

/**
 * Converts the number of days since the epoch to the date
 * @param days - number of days since the epoch
 * @return date/*  www .  ja  v  a2  s.co m*/
 */
public static Date epochDays2Date(int days) {
    Calendar cal = new GregorianCalendar();
    cal.setTimeInMillis(0);
    cal.add(Calendar.DAY_OF_YEAR, days);
    return cal.getTime();
}

From source file:TimeLib.java

/**
 * Get the timestamp resulting from clearing (setting to zero) all time
 * values less than or equal to that of the given field. For example,
 * clearing to {@link Calendar#HOUR} will floor the time to nearest
 * hour which occurred before or at the given time (e.g., 1:32
 * --> 1:30)./*  w  w  w . j a  v  a  2 s.c o  m*/
 * @param t the reference time
 * @param c a Calendar instance used to help compute the value, the
 * state of the Calendar will be overwritten.
 * @param field the time field to clear to, one of the
 * {@link java.util.Calendar} fields, or one of the extended fields
 * provided by this class (MILLENIUM, CENTURY, or DECADE).
 * @return the cleared time
 */
public static long getClearedTime(long t, Calendar c, int field) {
    c.setTimeInMillis(t);
    TimeLib.clearTo(c, field);
    return c.getTimeInMillis();
}

From source file:org.ambraproject.wombat.service.remote.CachedRemoteService.java

/**
 * Extract the timestamp from a cached object, or a default value.
 *
 * @param cached the cached object wrapper
 * @param <T>    the type of cached value
 * @return the timestamp//from www  . j av  a  2s .  co  m
 */
private static <T> Calendar getLastModified(CachedObject<? extends T> cached) {
    if (cached == null) {
        Calendar lastModified = Calendar.getInstance();
        lastModified.setTimeInMillis(0); // Set to beginning of epoch since it's not in the cache
        return lastModified;
    } else {
        return cached.timestamp;
    }
}