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:sk.lazyman.gizmo.util.GizmoUtils.java

public static Date clearTime(Date date) {
    if (date == null) {
        return null;
    }/*from   ww w  .ja  va 2  s.c om*/

    Calendar cal = Calendar.getInstance();
    cal.setTime(date);

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

    return cal.getTime();
}

From source file:gridrover.TravelEvent.java

/**
* Cause a rover to travel from one square to another.  May fail.
*//*w  w w. j av  a 2 s  . co m*/
protected void apply() {
    Calendar eventStartTime = (Calendar) startTime.clone();
    log.debug("Attempting to go " + command.getArgs()[0]);
    if (rover.go(command.getArgs()[0])) {
        eventStartTime.add(Calendar.MILLISECOND, 50000);
        rover.getControlInterface().commandSucceeded(command);
    } else {
        eventStartTime.add(Calendar.MILLISECOND, 50);
        rover.getControlInterface().commandFailed(command);
    }
    eventQueue.add(new CommandEvent(eventStartTime, eventQueue, rover));
}

From source file:com.fsatir.controller.MediaManagedBean.java

public void saveMedia() {
    try {/*from   w  w w  .j  a  va  2 s  . c  o  m*/
        media.setCategoryList(selectedCategoryList);
        media.setSource(QuestionSourceTypes.FROM_ADMIN.getSourceType());
        media.setLikeCount(0);
        media.setShareCount(0);
        media.setTweetID(Long.valueOf(Calendar.getInstance().get(Calendar.MILLISECOND)));
        SiteUser siteUser = (SiteUser) FacesContext.getCurrentInstance().getExternalContext().getSessionMap()
                .get("siteUser");
        media.setSiteUser(siteUser);
        media.setInsertDate(new Date());
        mediaService.saveMedia(media);
        mediaList = mediaService.listOfMedia();
        media = new Media();

    } catch (Exception ex) {
        Logger.getLogger(MediaManagedBean.class.getName()).log(Level.SEVERE, null, ex);
        ex.printStackTrace();
    }

}

From source file:lineage2.gameserver.model.entity.events.impl.ClanHallAuctionEvent.java

/**
 * Method reCalcNextTime.//from w w  w  .j a  v  a  2  s . c om
 * @param onStart boolean
 */
@Override
public void reCalcNextTime(boolean onStart) {
    clearActions();
    _onTimeActions.clear();

    Clan owner = getResidence().getOwner();

    _endSiegeDate.setTimeInMillis(0);
    if ((getResidence().getAuctionLength() == 0) && (owner == null)) {
        getResidence().getSiegeDate().setTimeInMillis(System.currentTimeMillis());
        getResidence().getSiegeDate().set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        getResidence().getSiegeDate().set(Calendar.HOUR_OF_DAY, 15);
        getResidence().getSiegeDate().set(Calendar.MINUTE, 0);
        getResidence().getSiegeDate().set(Calendar.SECOND, 0);
        getResidence().getSiegeDate().set(Calendar.MILLISECOND, 0);

        getResidence().setAuctionLength(7);
        getResidence().setAuctionMinBid(getResidence().getBaseMinBid());
        getResidence().setJdbcState(JdbcEntityState.UPDATED);
        getResidence().update();

        _onTimeActions.clear();
        addOnTimeAction(0, new StartStopAction(EVENT, true));
        addOnTimeAction(getResidence().getAuctionLength() * 86400, new StartStopAction(EVENT, false));

        _endSiegeDate.setTimeInMillis(getResidence().getSiegeDate().getTimeInMillis()
                + (getResidence().getAuctionLength() * 86400000L));

        registerActions();
    } else if ((getResidence().getAuctionLength() == 0) && (owner != null)) {
    } else {
        long endDate = getResidence().getSiegeDate().getTimeInMillis()
                + (getResidence().getAuctionLength() * 86400000L);
        if (endDate <= System.currentTimeMillis()) {
            getResidence().getSiegeDate().setTimeInMillis(System.currentTimeMillis());
        }

        _endSiegeDate.setTimeInMillis(getResidence().getSiegeDate().getTimeInMillis()
                + (getResidence().getAuctionLength() * 86400000L));

        _onTimeActions.clear();
        addOnTimeAction(0, new StartStopAction(EVENT, true));
        addOnTimeAction(getResidence().getAuctionLength() * 86400, new StartStopAction(EVENT, false));

        registerActions();
    }
}

From source file:com.gatf.executor.core.GatfFunctionHandler.java

public static String handleFunction(String function) {
    if (function.equals(BOOLEAN)) {
        Random rand = new Random();
        return String.valueOf(rand.nextBoolean());
    } else if (function.matches(DT_FMT_REGEX)) {
        Matcher match = datePattern.matcher(function);
        match.matches();//from   ww w  . ja va 2s .  c  o m
        SimpleDateFormat format = new SimpleDateFormat(match.group(1));
        return format.format(new Date());
    } else if (function.matches(DT_FUNC_FMT_REGEX)) {
        Matcher match = specialDatePattern.matcher(function);
        match.matches();
        String formatStr = match.group(1);
        String operation = match.group(2);
        int value = Integer.valueOf(match.group(3));
        String unit = match.group(4);
        SimpleDateFormat format = new SimpleDateFormat(formatStr);
        try {
            Date dt = format.parse(format.format(new Date()));
            Calendar cal = Calendar.getInstance();
            cal.setTime(dt);

            value = (operation.equals(MINUS) ? -value : value);
            if (unit.equals(YEAR)) {
                cal.add(Calendar.YEAR, value);
            } else if (unit.equals(MONTH)) {
                cal.add(Calendar.MONTH, value);
            } else if (unit.equals(DAY)) {
                cal.add(Calendar.DAY_OF_YEAR, value);
            } else if (unit.equals(HOUR)) {
                cal.add(Calendar.HOUR_OF_DAY, value);
            } else if (unit.equals(MINUITE)) {
                cal.add(Calendar.MINUTE, value);
            } else if (unit.equals(SECOND)) {
                cal.add(Calendar.SECOND, value);
            } else if (unit.equals(MILLISECOND)) {
                cal.add(Calendar.MILLISECOND, value);
            }
            return format.format(cal.getTime());
        } catch (Exception e) {
            throw new AssertionError("Invalid date format specified - " + formatStr);
        }
    } else if (function.equals(FLOAT)) {
        Random rand = new Random(12345678L);
        return String.valueOf(rand.nextFloat());
    } else if (function.equals(ALPHA)) {
        return RandomStringUtils.randomAlphabetic(10);
    } else if (function.equals(ALPHANUM)) {
        return RandomStringUtils.randomAlphanumeric(10);
    } else if (function.equals(NUMBER_PLUS)) {
        Random rand = new Random();
        return String.valueOf(rand.nextInt(1234567));
    } else if (function.equals(NUMBER_MINUS)) {
        Random rand = new Random();
        return String.valueOf(-rand.nextInt(1234567));
    } else if (function.equals(NUMBER)) {
        Random rand = new Random();
        boolean bool = rand.nextBoolean();
        return bool ? String.valueOf(rand.nextInt(1234567)) : String.valueOf(-rand.nextInt(1234567));
    } else if (function.matches(RANDOM_RANGE_REGEX)) {
        Matcher match = randRangeNum.matcher(function);
        match.matches();
        String min = match.group(1);
        String max = match.group(2);
        try {
            int nmin = Integer.parseInt(min);
            int nmax = Integer.parseInt(max);
            return String.valueOf(nmin + (int) (Math.random() * ((nmax - nmin) + 1)));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return null;
}

From source file:com.silverpeas.calendar.DateTimeTest.java

@Test
public void createsAtASpecifiedShorterDateTime() {
    Calendar now = getInstance();
    now.set(Calendar.SECOND, 0);/*  w  w  w  .jav  a  2s.c  om*/
    now.set(Calendar.MILLISECOND, 0);
    DateTime expected = new DateTime(now.getTime());
    DateTime actual = DateTime.dateTimeAt(now.get((Calendar.YEAR)), now.get(Calendar.MONTH),
            now.get(Calendar.DAY_OF_MONTH), now.get(Calendar.HOUR_OF_DAY), now.get(Calendar.MINUTE));
    assertEquals(expected.getTime(), actual.getTime(), 100);
}

From source file:TimeUtils.java

public static synchronized StringBuffer appendTime(StringBuffer sb, long timeStamp, boolean millisecond) {
    if (timeStamp == 0) {
        sb.append("n/a");
        return sb;

    }//from   ww  w  . j av  a2  s  .c o m
    if (singleCalendar == null) {
        singleCalendar = Calendar.getInstance();
        singleDate = new Date();
    }
    singleDate.setTime(timeStamp);
    singleCalendar.setTime(singleDate);

    StringUtils.appendD00(sb, singleCalendar.get(Calendar.HOUR_OF_DAY)).append(':');
    StringUtils.appendD00(sb, singleCalendar.get(Calendar.MINUTE)).append(':');
    StringUtils.appendD00(sb, singleCalendar.get(Calendar.SECOND));
    if (millisecond) {
        sb.append('.');
        StringUtils.appendD000(sb, singleCalendar.get(Calendar.MILLISECOND));
    }

    return sb;
}

From source file:com.netflix.genie.core.jpa.services.JpaJobPersistenceImplIntegrationTests.java

/**
 * Make sure we can delete jobs that were created before a given date.
 *//*  w  ww  .ja  v a  2 s  . c o m*/
@Test
public void canDeleteJobsCreatedBeforeDateWithMinTransactionAndPageSize() {

    // Try to delete a single job from before Jan 1, 2016
    final Calendar cal = Calendar.getInstance(JobConstants.UTC);
    cal.set(2016, Calendar.JANUARY, 1, 0, 0, 0);
    cal.set(Calendar.MILLISECOND, 0);

    final long deleted = this.jobPersistenceService.deleteBatchOfJobsCreatedBeforeDate(cal.getTime(), 1, 1);

    Assert.assertThat(deleted, Matchers.is(1L));
    Assert.assertThat(this.jobExecutionRepository.count(), Matchers.is(2L));
    Assert.assertThat(this.jobRequestRepository.count(), Matchers.is(2L));
    Assert.assertThat(this.jobRequestMetadataRepository.count(), Matchers.is(2L));
    Assert.assertThat(this.jobRepository.count(), Matchers.is(2L));
    Assert.assertNotNull(this.jobExecutionRepository.getOne(JOB_3_ID));
    Assert.assertNotNull(this.jobRequestRepository.getOne(JOB_3_ID));
    Assert.assertNotNull(this.jobRequestMetadataRepository.getOne(JOB_3_ID));
    Assert.assertNotNull(this.jobRepository.getOne(JOB_3_ID));
}

From source file:adalid.commons.util.TimeUtils.java

public static synchronized Date getDate(java.util.Date date) {
    if (date == null) {
        return currentDate();
    }/* w  ww  .j a va2s  .c  om*/
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(date.getTime());
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    return new Date(c.getTimeInMillis());
}

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

@Test
public void testAdjustExpiresSameDayPast() 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 a2  s . c o  m
    expected.add(Calendar.DAY_OF_WEEK, 7);

    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));
}