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:org.springmodules.validation.util.condition.date.IsBeforeDateCondition.java

/**
 * Checks whether the given calendar is chornologically before the calendar associated with this condition.
 *
 * @param calendar The calendar to be checked.
 * @return <code>true</code> if the given calender comes before the calendar associated with this condition,
 *         <code>false</code> otherwise.
 */// ww  w.  j  av a 2 s .  co m
protected boolean checkCalendar(Calendar calendar) {
    return later.getTimeInMillis() > calendar.getTimeInMillis();
}

From source file:com.sirma.itt.emf.time.ISO8601DateFormat.java

/**
 * Format date into ISO format.//from  w  w w. j  a  va2  s.  c  o m
 * 
 * @param isoDate
 *            the date to format
 * @return the ISO formatted string
 */
public static String format(Date isoDate) {
    if (isoDate == null) {
        return null;
    }
    // Note: always serialise to Gregorian Calendar
    Calendar calendar = new GregorianCalendar();
    calendar.setTime(isoDate);

    StringBuilder formatted = new StringBuilder(28);
    padInt(formatted, calendar.get(Calendar.YEAR), 4);
    formatted.append('-');
    padInt(formatted, calendar.get(Calendar.MONTH) + 1, 2);
    formatted.append('-');
    padInt(formatted, calendar.get(Calendar.DAY_OF_MONTH), 2);
    formatted.append('T');
    padInt(formatted, calendar.get(Calendar.HOUR_OF_DAY), 2);
    formatted.append(':');
    padInt(formatted, calendar.get(Calendar.MINUTE), 2);
    formatted.append(':');
    padInt(formatted, calendar.get(Calendar.SECOND), 2);
    formatted.append('.');
    padInt(formatted, calendar.get(Calendar.MILLISECOND), 3);

    TimeZone tz = calendar.getTimeZone();
    int offset = tz.getOffset(calendar.getTimeInMillis());
    formatted.append(getTimeZonePadding(offset));

    return formatted.toString();
}

From source file:org.springmodules.validation.util.condition.date.IsAfterDateCondition.java

/**
 * Checks whether the given calendar is chornologically after the calendar associated with this condition.
 *
 * @param calendar The calendar to be checked.
 * @return <code>true</code> if the given calender comes after the calendar associated with this condition,
 *         <code>false</code> otherwise.
 *//*from   w ww . ja  v  a  2s. co  m*/
protected boolean checkCalendar(Calendar calendar) {
    return earlier.getTimeInMillis() < calendar.getTimeInMillis();
}

From source file:com.swiftnav.sbp.loggers.JSONLogger.java

private long utc() {
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    return cal.getTimeInMillis() / 1000;
}

From source file:com.sirma.itt.emf.time.ISO8601DateFormat.java

/**
 * Format calendar instance into ISO format.
 * // w w  w.  ja  v a2 s.c  om
 * @param calendar
 *            the calendar instance to format
 * @return the ISO formatted string
 */
public static String format(Calendar calendar) {
    if (calendar == null) {
        return null;
    }

    StringBuilder formatted = new StringBuilder(28);
    padInt(formatted, calendar.get(Calendar.YEAR), 4);
    formatted.append('-');
    padInt(formatted, calendar.get(Calendar.MONTH) + 1, 2);
    formatted.append('-');
    padInt(formatted, calendar.get(Calendar.DAY_OF_MONTH), 2);
    formatted.append('T');
    padInt(formatted, calendar.get(Calendar.HOUR_OF_DAY), 2);
    formatted.append(':');
    padInt(formatted, calendar.get(Calendar.MINUTE), 2);
    formatted.append(':');
    padInt(formatted, calendar.get(Calendar.SECOND), 2);
    formatted.append('.');
    padInt(formatted, calendar.get(Calendar.MILLISECOND), 3);

    TimeZone tz = calendar.getTimeZone();
    int offset = tz.getOffset(calendar.getTimeInMillis());
    formatted.append(getTimeZonePadding(offset));

    return formatted.toString();
}

From source file:slash.navigation.rest.ReadRequest.java

public Long getLastModified() throws IOException {
    String lastModified = getHeader(LAST_MODIFIED);
    if (lastModified == null)
        return null;

    try {/*from w  ww  . j ava2 s.co m*/
        Calendar calendar = parseDate(lastModified);
        return calendar.getTimeInMillis();
    } catch (ParseException e) {
        throw new IOException("Cannot parse last modified: " + lastModified, e);
    }
}

From source file:org.atomspace.ultrahouse3000.translator.Message2DocumentTranslator.java

void addCalenderInformation(Message message) {
    Calendar cal = Calendar.getInstance();
    message.setHeader("timestamp", cal.getTimeInMillis());
    message.setHeader("calendarYear", cal.get(Calendar.YEAR));
    message.setHeader("calendarDayOfMonth", cal.get(Calendar.DAY_OF_MONTH));
    message.setHeader("calendarMonth", cal.get(Calendar.MONTH));
    message.setHeader("calendarDayOfYear", cal.get(Calendar.DAY_OF_YEAR));
    message.setHeader("calendarHourOfDay", cal.get(Calendar.HOUR_OF_DAY));
    message.setHeader("calendarMinute", cal.get(Calendar.MINUTE));
    message.setHeader("calendarSecond", cal.get(Calendar.SECOND));
    message.setHeader("calendarWeekOfYear", cal.get(Calendar.WEEK_OF_YEAR));
    message.setHeader("calendarDayOfWeek", cal.get(Calendar.DAY_OF_WEEK));

}

From source file:ru.anr.base.BaseParent.java

/**
 * @param startDate/*from  w  w  w.  j ava  2 s .  c  o  m*/
 *            Start date
 * @param endDate
 *            End date
 * @param locale
 *            Locale
 * @return formatted period without seconds
 */
public static String formatPeriodWithoutSeconds(Calendar startDate, Calendar endDate, String locale) {

    Period period = new Period(startDate.getTimeInMillis(), endDate.getTimeInMillis(),
            PeriodType.standard().withSecondsRemoved().withMillisRemoved());

    String l = locale == null ? Locale.getDefault().toString() : locale;
    return PeriodFormat.wordBased(Locale.forLanguageTag(l.replaceAll("_", "-"))).print(period);
}

From source file:free.yhc.feeder.model.Utils.java

/**
 * NOTE/*w w w .j  a  va 2s .c  om*/
 * 'secs' array is [in/out] argument.
 * @param calNow
 * @param secs
 *   [in/out] After return, array is sorted by ascending numerical order.
 *   00:00:00 based value.
 *   seconds since 00:00:00 (12:00 AM)
 *   (negative value is NOT ALLOWED)
 *   Order may be changed (sorted) to ascending order.
 * @return
 *   time(ms based on 1970) to next nearest time of given second-of-day array.
 */
public static long nextNearestTime(Calendar calNow, long[] secs) {
    eAssert(secs.length > 0);
    Calendar cal = Calendar.getInstance();
    cal.setTime(calNow.getTime());

    long now = cal.getTimeInMillis();
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    long dayBase = cal.getTimeInMillis();
    long dayTime = now - dayBase;
    if (dayTime < 0)
        dayTime = 0; // To compensate error from '/' operation.

    Arrays.sort(secs);
    // Just linear search... it's enough.
    // Binary search is not considered yet.(over-engineering)
    for (long s : secs) {
        eAssert(s >= 0);
        if (s * 1000 > dayTime)
            return dayTime + s * 1000;
    }
    // All scheduled time is passed for day.
    // smallest of tomorrow is nearest one.
    return dayBase + DAY_IN_MS + secs[0] * 1000;
}

From source file:com.solace.data.caching.TestService.java

public long find(long id) throws Exception {
    Calendar c = Calendar.getInstance();

    long now = c.getTimeInMillis();

    Parent p = DaoManager.getParentDao().findById(id);

    assertNotNull(p);//from  w w w  .j  av  a2s  .  com

    return c.getTimeInMillis() - now;
}