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:net.solarnetwork.node.backup.test.FileSystemBackupServiceTest.java

@Test
public void backupOne() throws IOException, InterruptedException {
    final ClassPathResource testResource = new ClassPathResource("test-context.xml",
            AbstractNodeTransactionalTest.class);
    final BackupService bs = service;
    final List<BackupResource> resources = new ArrayList<BackupResource>(1);
    final Calendar now = new GregorianCalendar();
    now.set(Calendar.MILLISECOND, 0);
    resources.add(new ResourceBackupResource(testResource, "test.xml"));
    Backup result = bs.performBackup(resources);
    assertNotNull(result);// ww  w  .  j  a  v  a  2 s .co m
    assertNotNull(result.getDate());
    assertTrue(!now.after(result.getDate()));
    assertNotNull(result.getKey());
    assertTrue(result.isComplete());

    // now let's verify we can get that file back out of the backup
    Collection<Backup> backups = bs.getAvailableBackups();
    assertNotNull(backups);
    assertEquals(1, backups.size());
    Backup b = backups.iterator().next();
    assertEquals(result.getKey(), b.getKey());
    assertEquals(result.getDate().getTime(), b.getDate().getTime());

    int count = 0;
    final BackupResourceIterable backupResources = bs.getBackupResources(b);
    try {
        for (BackupResource r : backupResources) {
            count++;
            assertEquals("test.xml", r.getBackupPath());
            Assert.assertArrayEquals(FileCopyUtils.copyToByteArray(testResource.getInputStream()),
                    FileCopyUtils.copyToByteArray(r.getInputStream()));
        }
    } finally {
        backupResources.close();
    }
    assertEquals("Should only have one backup resource", 1, count);
}

From source file:com.epam.training.storefront.forms.validation.PaymentDetailsValidator.java

protected Calendar getCalendarResetTime() {
    final Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    return calendar;
}

From source file:Dates.java

/**
 * Returns a clone but with 23:59:59:999 for hours, minutes, seconds and milliseconds. <p>
 * //from  w  ww.j  ava  2s.  c  om
 * @return The same date sent as argument (a new date is not created). If null
 *      if sent a null is returned.
 */
public static Date cloneWith2359(Date date) {
    if (date == null)
        return null;
    Date result = (Date) date.clone();
    Calendar cal = Calendar.getInstance();
    cal.setTime(result);
    cal.set(Calendar.HOUR_OF_DAY, 23);
    cal.set(Calendar.MINUTE, 59);
    cal.set(Calendar.SECOND, 59);
    cal.set(Calendar.MILLISECOND, 999);
    result.setTime(cal.getTime().getTime());
    return result;
}

From source file:com.collabnet.ccf.core.utils.DateUtil.java

public static boolean isAbsoluteDateInTimezone(Date date, String timeZone) {
    Calendar cal = new GregorianCalendar(TimeZone.getTimeZone(timeZone));
    cal.setLenient(false);//from   www . j  ava 2 s .c om
    cal.setTime(date);
    int hour = cal.get(Calendar.HOUR_OF_DAY);
    int minutes = cal.get(Calendar.MINUTE);
    int seconds = cal.get(Calendar.SECOND);
    int milliseconds = cal.get(Calendar.MILLISECOND);
    if (hour == 0 && minutes == 0 && seconds == 0 && milliseconds == 0) {
        return true;
    } else {
        return false;
    }
}

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

@Test
public void testAdjustExpiresSameDayFuture() throws Exception {

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

    Calendar expected = Calendar.getInstance();
    expected.setTime(actual.getTime());//from ww w.  j av  a 2 s .c om

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

From source file:com.raspi.chatapp.util.storage.MessageHistory.java

public ChatEntry[] getChats() {
    SQLiteDatabase db = mDbHelper.getReadableDatabase();
    Cursor chats = db.query(MessageHistoryContract.ChatEntry.TABLE_NAME_ALL_CHATS,
            new String[] { MessageHistoryContract.ChatEntry.COLUMN_NAME_BUDDY_ID,
                    MessageHistoryContract.ChatEntry.COLUMN_NAME_NAME },
            null, null, null, null, MessageHistoryContract.ChatEntry.COLUMN_NAME_NAME);
    int chatCount = chats.getCount();
    ChatEntry[] resultChats = new ChatEntry[chatCount];
    int i = 0;//from w  ww . ja v  a 2  s.c  o  m
    chats.moveToFirst();
    if (chats.getCount() > 0)
        do {
            String buddyId = chats.getString(0);
            String name = chats.getString(1);
            MessageArrayContent mac = getLastMessage(buddyId);

            if (mac instanceof TextMessage) {
                TextMessage msg = (TextMessage) mac;

                String lastMessageDate;
                Date msgTime = new Date(msg.time);
                Calendar startOfDay = Calendar.getInstance();
                startOfDay.set(Calendar.HOUR_OF_DAY, 0);
                startOfDay.set(Calendar.MINUTE, 0);
                startOfDay.set(Calendar.SECOND, 0);
                startOfDay.set(Calendar.MILLISECOND, 0);
                long diff = startOfDay.getTimeInMillis() - msgTime.getTime();
                if (diff <= 0)
                    lastMessageDate = String.format(context.getResources().getString(R.string.time), msgTime);
                else if (diff > 1000 * 60 * 60 * 24)
                    lastMessageDate = String.format(context.getResources().getString(R.string.date), msgTime);
                else
                    lastMessageDate = context.getResources().getString(R.string.last_message_yesterday);

                resultChats[i] = new ChatEntry(buddyId, name, MessageHistory.TYPE_TEXT, msg.status,
                        lastMessageDate, ((msg.left) ? name + ": " : "") + msg.message, !msg.left);
            } else if (mac instanceof ImageMessage) {
                ImageMessage msg = (ImageMessage) mac;

                String lastMessageDate;
                Date msgTime = new Date(msg.time);
                Calendar startOfDay = Calendar.getInstance();
                startOfDay.set(Calendar.HOUR_OF_DAY, 0);
                startOfDay.set(Calendar.MINUTE, 0);
                startOfDay.set(Calendar.SECOND, 0);
                startOfDay.set(Calendar.MILLISECOND, 0);
                long diff = startOfDay.getTimeInMillis() - msgTime.getTime();
                if (diff <= 0)
                    lastMessageDate = String.format(context.getResources().getString(R.string.time), msgTime);
                else if (diff > 1000 * 60 * 60 * 24)
                    lastMessageDate = String.format(context.getResources().getString(R.string.date), msgTime);
                else
                    lastMessageDate = context.getResources().getString(R.string.last_message_yesterday);
                msg.description += "".equals(msg.description) ? context.getResources().getString(R.string.image)
                        : "";

                resultChats[i] = new ChatEntry(buddyId, name, MessageHistory.TYPE_IMAGE, msg.status,
                        lastMessageDate, msg.description, !msg.left);
            }
            i++;
        } while (chats.move(1));
    chats.close();
    db.close();
    return resultChats;
}

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

private XYSeries createXYSeries(String title, Iterator it) {
    XYSeries series = new XYSeries(title);

    while (it.hasNext()) {
        CvsRevision rev = (CvsRevision) it.next();

        Calendar cal = Calendar.getInstance();
        cal.setTime(rev.getDate());/* w  w w.  ja  va 2 s  .  c o  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));
    }

    return series;
}

From source file:org.kuali.mobility.sakai.controllers.SakaiController.java

@RequestMapping(method = RequestMethod.GET)
public String getSites(HttpServletRequest request, @RequestParam(value = "date", required = false) String date,
        Model uiModel) {//  w  w w.java  2s  .  c om
    User user = (User) request.getSession().getAttribute(Constants.KME_USER_KEY);
    Home home = sakaiSiteService.findSakaiHome(user.getUserId(), date);
    uiModel.addAttribute("home", home);
    uiModel.addAttribute("tabCount",
            (home.getCourses() != null && home.getCourses().size() > 0 ? 2 : 0)
                    + (home.getProjects() != null && home.getProjects().size() > 0 ? 1 : 0)
                    + (home.getOther() != null && home.getOther().size() > 0 ? 1 : 0));

    Calendar todayDate = Calendar.getInstance();
    if (date != null) {
        try {
            todayDate.setTime(Constants.DateFormat.queryStringDateFormat.getFormat().parse(date));
        } catch (Exception e) {
        }
    }
    todayDate.set(Calendar.HOUR, 0);
    todayDate.set(Calendar.MINUTE, 0);
    todayDate.set(Calendar.SECOND, 0);
    todayDate.set(Calendar.MILLISECOND, 0);
    uiModel.addAttribute("todayDisplay",
            Constants.DateFormat.displayDateFormat.getFormat().format(todayDate.getTime()));
    todayDate.add(Calendar.DATE, -1);
    uiModel.addAttribute("yesterday",
            Constants.DateFormat.queryStringDateFormat.getFormat().format(todayDate.getTime()));
    uiModel.addAttribute("yesterdayButton",
            Constants.DateFormat.buttonDateFormat.getFormat().format(todayDate.getTime()));
    todayDate.add(Calendar.DATE, 2);
    uiModel.addAttribute("tomorrow",
            Constants.DateFormat.queryStringDateFormat.getFormat().format(todayDate.getTime()));
    uiModel.addAttribute("tomorrowButton",
            Constants.DateFormat.buttonDateFormat.getFormat().format(todayDate.getTime()));

    return "sakai/home";
}

From source file:ilarkesto.integration.max.internet.MaxSession.java

public void executeSetRoomTemporaryMode(MaxRoom room, float temperature, Date until) {
    if (room == null)
        throw new IllegalArgumentException("room == null");
    if (until == null)
        throw new IllegalArgumentException("until == null");

    Calendar cal = Calendar.getInstance();
    cal.setTime(until);/*from  w  w w .j  a  v  a  2  s.  co  m*/
    cal.set(Calendar.MILLISECOND, 0);
    cal.set(Calendar.SECOND, 0);
    int minute = cal.get(Calendar.MINUTE);
    if (minute == 30 || minute == 0) {
        // no change
    } else if (minute > 27) {
        cal.roll(Calendar.HOUR_OF_DAY, 1);
        cal.set(Calendar.MINUTE, 0);
    } else {
        cal.set(Calendar.MINUTE, 30);
    }
    until = cal.getTime();

    Map<String, String> extra = new LinkedHashMap<String, String>();
    extra.put("c0-e2", "string:" + room.getId());
    extra.put("c0-e3", "Date:" + until.getTime());
    extra.put("c0-e4", "number:" + temperature);
    extra.put("c0-e1",
            "Object_MaxSetRoomTemporaryMode:{roomId:reference:c0-e2, date:reference:c0-e3, temperature:reference:c0-e4}");
    executeApiMethod(true, "setClientCommands", extra, "Array:[reference:c0-e1]");
    log.info("Command transmitted:", "SetRoomTemporaryMode", temperature, until, room.getName());
}

From source file:com.gargoylesoftware.htmlunit.httpclient.HtmlUnitExpiresHandler.java

@Override
public void parse(final SetCookie cookie, String value) throws MalformedCookieException {
    if (value.startsWith("\"") && value.endsWith("\"")) {
        value = value.substring(1, value.length() - 1);
    }//www. j  a va 2s  .c  om
    value = value.replaceAll("[ ,:-]+", " ");

    Date startDate = null;
    String[] datePatterns = DEFAULT_DATE_PATTERNS;

    if (null != browserVersion_) {
        if (browserVersion_.hasFeature(HTTP_COOKIE_START_DATE_1970)) {
            startDate = HtmlUnitBrowserCompatCookieSpec.DATE_1_1_1970;
        }

        if (browserVersion_.hasFeature(HTTP_COOKIE_EXTENDED_DATE_PATTERNS_1)) {
            datePatterns = EXTENDED_DATE_PATTERNS_1;
        }

        if (browserVersion_.hasFeature(HTTP_COOKIE_EXTENDED_DATE_PATTERNS_2)) {
            final Calendar calendar = Calendar.getInstance(Locale.ROOT);
            calendar.setTimeZone(DateUtils.GMT);
            calendar.set(1969, Calendar.JANUARY, 1, 0, 0, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            startDate = calendar.getTime();

            datePatterns = EXTENDED_DATE_PATTERNS_2;
        }
    }

    final Date expiry = DateUtils.parseDate(value, datePatterns, startDate);
    cookie.setExpiryDate(expiry);
}