Example usage for java.util Calendar MILLISECOND

List of usage examples for java.util Calendar MILLISECOND

Introduction

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

Prototype

int MILLISECOND

To view the source code for java.util Calendar MILLISECOND.

Click Source Link

Document

Field number for get and set indicating the millisecond within the second.

Usage

From source file:com.adobe.acs.commons.http.headers.impl.WeeklyExpiresHeaderFilterTest.java

@Test
public void testAdjustExpiresFutureWeekday() throws Exception {

    Calendar actual = Calendar.getInstance();
    actual.set(Calendar.SECOND, 0);
    actual.set(Calendar.MILLISECOND, 0);

    Calendar expected = Calendar.getInstance();
    expected.setTime(actual.getTime());/*from  w  w  w. j  a v  a2s  .  c o  m*/
    expected.add(Calendar.DAY_OF_WEEK, 2);

    int dayOfweek = expected.get(Calendar.DAY_OF_WEEK);
    properties.put(WeeklyExpiresHeaderFilter.PROP_EXPIRES_DAY_OF_WEEK, dayOfweek);

    filter.doActivate(componentContext);
    filter.adjustExpires(actual);

    assertTrue(DateUtils.isSameInstant(expected, actual));
    assertEquals(dayOfweek, actual.get(Calendar.DAY_OF_WEEK));
}

From source file:com.silverpeas.jcrutil.RandomGenerator.java

public static Calendar getRandomCalendar() {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.DAY_OF_MONTH, getRandomDay());
    calendar.set(Calendar.MONTH, getRandomMonth());
    calendar.set(Calendar.YEAR, getRandomYear());
    calendar.set(Calendar.HOUR_OF_DAY, getRandomHour());
    calendar.set(Calendar.MINUTE, getRandomMinutes());
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    calendar.setLenient(false);//  w  ww .  j  av  a2  s  . c o m
    try {
        calendar.getTime();
    } catch (IllegalArgumentException ie) {
        return getRandomCalendar();
    }
    return calendar;
}

From source file:Time.java

public void addMilliSeconds(int nMilliSeconds) {
    calendar_.add(Calendar.MILLISECOND, nMilliSeconds);
}

From source file:DateTime.java

/**
 * Parses an RFC 3339 date/time value./*ww w .j ava 2  s .c om*/
 */
public static DateTime parseRfc3339(String str) throws NumberFormatException {
    try {
        Calendar dateTime = new GregorianCalendar(GMT);
        int year = Integer.parseInt(str.substring(0, 4));
        int month = Integer.parseInt(str.substring(5, 7)) - 1;
        int day = Integer.parseInt(str.substring(8, 10));
        int tzIndex;
        int length = str.length();
        boolean dateOnly = length <= 10 || Character.toUpperCase(str.charAt(10)) != 'T';
        if (dateOnly) {
            dateTime.set(year, month, day);
            tzIndex = 10;
        } else {
            int hourOfDay = Integer.parseInt(str.substring(11, 13));
            int minute = Integer.parseInt(str.substring(14, 16));
            int second = Integer.parseInt(str.substring(17, 19));
            dateTime.set(year, month, day, hourOfDay, minute, second);
            if (str.charAt(19) == '.') {
                int milliseconds = Integer.parseInt(str.substring(20, 23));
                dateTime.set(Calendar.MILLISECOND, milliseconds);
                tzIndex = 23;
            } else {
                tzIndex = 19;
            }
        }
        Integer tzShiftInteger = null;
        long value = dateTime.getTimeInMillis();
        if (length > tzIndex) {
            int tzShift;
            if (Character.toUpperCase(str.charAt(tzIndex)) == 'Z') {
                tzShift = 0;
            } else {
                tzShift = Integer.parseInt(str.substring(tzIndex + 1, tzIndex + 3)) * 60
                        + Integer.parseInt(str.substring(tzIndex + 4, tzIndex + 6));
                if (str.charAt(tzIndex) == '-') {
                    tzShift = -tzShift;
                }
                value -= tzShift * 60000;
            }
            tzShiftInteger = tzShift;
        }
        return new DateTime(dateOnly, value, tzShiftInteger);
    } catch (StringIndexOutOfBoundsException e) {
        throw new NumberFormatException("Invalid date/time format.");
    }
}

From source file:de.berlios.statcvs.xml.report.CommitActivityChart.java

private void addToXYSeries(XYSeries series, CvsRevision rev) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(rev.getDate());/*from   w  ww  . j  a  v  a2  s .co  m*/
    double hour = cal.get(Calendar.HOUR_OF_DAY);
    double minutes = cal.get(Calendar.MINUTE);

    // clear time info
    cal.clear(Calendar.HOUR);
    cal.clear(Calendar.HOUR_OF_DAY);
    cal.clear(Calendar.MINUTE);
    cal.clear(Calendar.SECOND);
    cal.clear(Calendar.MILLISECOND);

    series.add(cal.getTime().getTime(), hour + (minutes / 60));
}

From source file:DateUtils.java

/**
 * Get FTP date.//from   w  w  w .  j  a  va2s .  c om
 */
public final static String getFtpDate(long millis) {
    StringBuffer sb = new StringBuffer(20);
    Calendar cal = new GregorianCalendar();
    cal.setTimeInMillis(millis);

    // year
    sb.append(cal.get(Calendar.YEAR));

    // month
    int month = cal.get(Calendar.MONTH) + 1;
    if (month < 10) {
        sb.append('0');
    }
    sb.append(month);

    // date
    int date = cal.get(Calendar.DATE);
    if (date < 10) {
        sb.append('0');
    }
    sb.append(date);

    // hour
    int hour = cal.get(Calendar.HOUR_OF_DAY);
    if (hour < 10) {
        sb.append('0');
    }
    sb.append(hour);

    // minute
    int min = cal.get(Calendar.MINUTE);
    if (min < 10) {
        sb.append('0');
    }
    sb.append(min);

    // second
    int sec = cal.get(Calendar.SECOND);
    if (sec < 10) {
        sb.append('0');
    }
    sb.append(sec);

    // millisecond
    sb.append('.');
    int milli = cal.get(Calendar.MILLISECOND);
    if (milli < 100) {
        sb.append('0');
    }
    if (milli < 10) {
        sb.append('0');
    }
    sb.append(milli);
    return sb.toString();
}

From source file:it.infn.ct.security.utilities.LDAPCleaner.java

private void followingChecks(int days) {
    _log.info("Check users who have not extended yet");
    Calendar cal = GregorianCalendar.getInstance();
    cal.add(Calendar.DAY_OF_YEAR, days);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);//from   w  w  w  .j  a  v  a2 s . c o  m
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

    Calendar calEnd = GregorianCalendar.getInstance();
    calEnd.setTime(cal.getTime());
    calEnd.add(Calendar.DAY_OF_YEAR, 1);

    Session ses = factory.openSession();

    List lstUserUpdates = ses.createCriteria(UserConfirmUpdate.class)
            .add(Restrictions.between("timelimit", cal.getTime(), calEnd.getTime()))
            .add(Restrictions.eq("updated", Boolean.FALSE)).list();

    for (UserConfirmUpdate ucu : (List<UserConfirmUpdate>) lstUserUpdates) {
        UserRequest ur = LDAPUtils.getUser(ucu.getUsername());

        sendUserRemainder(ur, days);
    }

    ses.close();

}

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.util.DateUtils.java

/**
 * Return the next day from the given day (the next day at 00:00)
 *
 * @param day the day to calculate the next day for
 * @return the next day from the given day
 *///from w w w  . ja  v  a2s  . co m
public static Calendar getNextDayFrom(final Calendar day) {

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

    // Next day
    day.add(Calendar.DAY_OF_YEAR, 1);

    return day;
}

From source file:me.crime.database.Crime.java

private void init(String cc) {
     StringBuffer buff = new StringBuffer();

     Calendar now = Calendar.getInstance(TimeZone.getTimeZone("GMT"));

     buff.append(String.format("%02d", now.get(Calendar.MONTH) + 1));
     buff.append(String.format("%02d", now.get(Calendar.DAY_OF_MONTH)));
     buff.append(now.get(Calendar.YEAR) + ".");
     buff.append(String.format("%02d", now.get(Calendar.HOUR_OF_DAY)));
     buff.append(String.format("%02d", now.get(Calendar.MINUTE)));
     buff.append(String.format("%02d", now.get(Calendar.SECOND)) + ".");
     buff.append(String.format("%03d", now.get(Calendar.MILLISECOND)) + "." + cc);

     crimeNumber_ = buff.toString();//from   www. j  a  v a2s. c  om
 }

From source file:com.adobe.acs.commons.http.headers.impl.MonthlyExpiresHeaderFilterTest.java

@Test
public void testAdjustExpiresFutureDay() throws Exception {

    Calendar actual = Calendar.getInstance();
    actual.set(Calendar.SECOND, 0);
    actual.set(Calendar.MILLISECOND, 0);

    Calendar expected = Calendar.getInstance();
    expected.setTime(actual.getTime());/*from   ww w .  j  a  v a  2 s. co  m*/
    expected.add(Calendar.DAY_OF_MONTH, 5);

    actual.set(Calendar.DAY_OF_MONTH, 15);

    final int month = expected.get(Calendar.MONTH);
    properties.put(MonthlyExpiresHeaderFilter.PROP_EXPIRES_DAY_OF_MONTH, expected.get(Calendar.DAY_OF_MONTH));

    filter.doActivate(componentContext);
    filter.adjustExpires(actual);

    assertTrue(DateUtils.isSameInstant(expected, actual));
    assertEquals(month, actual.get(Calendar.MONTH));
}