List of usage examples for java.util Calendar MILLISECOND
int MILLISECOND
To view the source code for java.util Calendar MILLISECOND.
Click Source Link
get
and set
indicating the millisecond within the second. From source file:com.netflix.genie.web.tasks.leader.DatabaseCleanupTaskUnitTests.java
/** * Make sure the run method passes in the expected date. */// w w w. j a va 2 s. c om @Test public void canRun() { final int days = 5; final int negativeDays = -1 * days; final int pageSize = 10; final int maxDeleted = 10_000; Mockito.when(this.cleanupProperties.getRetention()).thenReturn(days).thenReturn(negativeDays); Mockito.when(this.cleanupProperties.getPageSize()).thenReturn(pageSize); Mockito.when(this.cleanupProperties.getMaxDeletedPerTransaction()).thenReturn(maxDeleted); final ArgumentCaptor<Date> argument = ArgumentCaptor.forClass(Date.class); final long deletedCount1 = 6L; final long deletedCount2 = 18L; final long deletedCount3 = 2L; Mockito.when(this.jobPersistenceService.deleteBatchOfJobsCreatedBeforeDate(Mockito.any(Date.class), Mockito.anyInt(), Mockito.anyInt())).thenReturn(deletedCount1).thenReturn(0L) .thenReturn(deletedCount2).thenReturn(deletedCount3).thenReturn(0L); // The multiple calendar instances are to protect against running this test when the day flips final Calendar before = Calendar.getInstance(JobConstants.UTC); this.task.run(); Assert.assertThat(this.numDeletedJobs.get(), Matchers.is(deletedCount1)); Mockito.verify(this.deletionTimerId, Mockito.times(1)).withTags(MetricsUtils.newSuccessTagsMap()); this.task.run(); final Calendar after = Calendar.getInstance(JobConstants.UTC); Assert.assertThat(this.numDeletedJobs.get(), Matchers.is(deletedCount2 + deletedCount3)); Mockito.verify(this.deletionTimerId, Mockito.times(2)).withTags(MetricsUtils.newSuccessTagsMap()); Mockito.verify(this.deletionTimer, Mockito.times(2)).record(Mockito.anyLong(), Mockito.eq(TimeUnit.NANOSECONDS)); if (before.get(Calendar.DAY_OF_YEAR) == after.get(Calendar.DAY_OF_YEAR)) { Mockito.verify(this.jobPersistenceService, Mockito.times(5)).deleteBatchOfJobsCreatedBeforeDate( argument.capture(), Mockito.eq(maxDeleted), Mockito.eq(pageSize)); final Calendar date = Calendar.getInstance(JobConstants.UTC); date.set(Calendar.HOUR_OF_DAY, 0); date.set(Calendar.MINUTE, 0); date.set(Calendar.SECOND, 0); date.set(Calendar.MILLISECOND, 0); date.add(Calendar.DAY_OF_YEAR, negativeDays); Assert.assertThat(argument.getAllValues().get(0), Matchers.is(date.getTime())); Assert.assertThat(argument.getAllValues().get(1), Matchers.is(date.getTime())); } }
From source file:TimeLib.java
/** * Get a timestamp for the given hour, minute, and second. The date will * be assumed to be January 1, 1970.//from w w w. j av a 2 s. co m * @param c a Calendar to use to help compute the result. The state of the * Calendar will be overwritten. * @param hour the hour, on a 24 hour clock * @param minute the minute value * @param second the seconds value * @return the timestamp for the given date */ public static long getTime(Calendar c, int hour, int minute, int second) { c.clear(Calendar.MILLISECOND); c.set(1970, 0, 1, hour, minute, second); return c.getTimeInMillis(); }
From source file:de.csdev.ebus.command.datatypes.ext.EBusTypeDate.java
@Override public byte[] encodeInt(Object data) throws EBusTypeException { IEBusType<BigDecimal> bcdType = types.getType(EBusTypeBCD.TYPE_BCD); IEBusType<BigDecimal> wordType = types.getType(EBusTypeWord.TYPE_WORD); IEBusType<BigDecimal> charType = types.getType(EBusTypeChar.TYPE_CHAR); Calendar calendar = null;//ww w.ja v a 2s . com byte[] result = new byte[this.getTypeLength()]; if (data instanceof EBusDateTime) { calendar = ((EBusDateTime) data).getCalendar(); } else if (data instanceof Calendar) { calendar = (Calendar) data; } // set date to midnight calendar = (Calendar) calendar.clone(); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); if (calendar != null) { if (StringUtils.equals(variant, DEFAULT)) { int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); dayOfWeek = dayOfWeek == 1 ? 7 : dayOfWeek - 1; result = new byte[] { bcdType.encode(calendar.get(Calendar.DAY_OF_MONTH))[0], bcdType.encode(calendar.get(Calendar.MONTH) + 1)[0], bcdType.encode(dayOfWeek)[0], bcdType.encode(calendar.get(Calendar.YEAR) % 100)[0] }; } else if (StringUtils.equals(variant, SHORT)) { result = new byte[] { bcdType.encode(calendar.get(Calendar.DAY_OF_MONTH))[0], bcdType.encode(calendar.get(Calendar.MONTH) + 1)[0], bcdType.encode(calendar.get(Calendar.YEAR) % 100)[0] }; } else if (StringUtils.equals(variant, HEX)) { int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); dayOfWeek = dayOfWeek == 1 ? 7 : dayOfWeek - 1; result = new byte[] { charType.encode(calendar.get(Calendar.DAY_OF_MONTH))[0], charType.encode(calendar.get(Calendar.MONTH) + 1)[0], charType.encode(dayOfWeek)[0], charType.encode(calendar.get(Calendar.YEAR) % 100)[0] }; } else if (StringUtils.equals(variant, HEX_SHORT)) { result = new byte[] { charType.encode(calendar.get(Calendar.DAY_OF_MONTH))[0], charType.encode(calendar.get(Calendar.MONTH) + 1)[0], charType.encode(calendar.get(Calendar.YEAR) % 100)[0] }; } else if (StringUtils.equals(variant, DAYS)) { long millis = calendar.getTimeInMillis(); calendar.clear(); calendar.set(1900, 0, 1, 0, 0); long millis1900 = calendar.getTimeInMillis(); BigDecimal days = new BigDecimal(millis - millis1900); days = days.divide(BigDecimal.valueOf(86400000), 0, RoundingMode.HALF_UP); result = wordType.encode(days); } } return result; }
From source file:com.athena.peacock.common.core.util.XMLGregorialCalendarUtil.java
/** * <pre>//www . ja v a2s . com * YYYY-MM-DDTHH:MI:SS.SSS+09:00 ? ?(:2007-02-13T10:25:05.986+07:00) ? GregorianCalendar ?. * </pre> * * @param stringTypeDate YYYY-MM-DDTHH:MI:SS.SSS+09:00 ? ?(:2007-02-13T10:25:05.986+07:00) * @return ? GregorianCalendar */ private static GregorianCalendar gmtStringToGregorianCalendar(String stringTypeDate) throws DatatypeConfigurationException { String yyyy = stringTypeDate.substring(0, 4); String mm = stringTypeDate.substring(5, 7); String dd = stringTypeDate.substring(8, 10); String hh = "00"; String mi = "00"; String ss = "00"; String ms = "00"; String tz = null; if (stringTypeDate.length() > 23) { hh = stringTypeDate.substring(11, 13); mi = stringTypeDate.substring(14, 16); ss = stringTypeDate.substring(17, 19); ms = stringTypeDate.substring(20, 23); tz = stringTypeDate.substring(23); } else { tz = stringTypeDate.substring(10); //tz = "+09:00"; } if (tz.equals("Z")) { tz = "UTC"; } else { tz = "GMT" + tz; } int iyyyy = Integer.parseInt(yyyy); int imm = Integer.parseInt(mm) - 1; int idd = Integer.parseInt(dd); int ihh = Integer.parseInt(hh); int imi = Integer.parseInt(mi); int iss = Integer.parseInt(ss); int ims = Integer.parseInt(ms); Calendar c = Calendar.getInstance(); c.setTimeZone(TimeZone.getTimeZone(tz)); c.set(iyyyy, imm, idd, ihh, imi, iss); c.set(Calendar.MILLISECOND, ims); GregorianCalendar cal = new GregorianCalendar(); cal.setTime(c.getTime()); cal.setTimeZone(TimeZone.getTimeZone("ROK")); return cal; }
From source file:helper.util.DateHelper.java
/** * @param start date already set to full day boundary (midnight) * @param end date already set to full day boundary (midnight) **///from ww w . j a v a 2 s . c o m private static CalendarRange calculateRangeBeforeEnd(Calendar start, Calendar end, int days) { start.add(Calendar.DATE, -(days + 1)); start.add(Calendar.MINUTE, -1); start.add(Calendar.SECOND, 59); start.add(Calendar.MILLISECOND, 999); return new CalendarRange(start, end); }
From source file:com.qut.middleware.saml2.SAML2Test.java
private XMLGregorianCalendar generateXMLCalendar(int offset) { SimpleTimeZone gmt;/* w w w . j a v a 2 s .c om*/ GregorianCalendar calendar; XMLGregorianCalendar xmlCalendar; /* GMT timezone TODO: I am sure this isn't correct need to ensure we set GMT */ // GMT or UTC ?? gmt = new SimpleTimeZone(0, "UTC"); calendar = new GregorianCalendar(gmt); calendar.add(Calendar.MILLISECOND, offset); xmlCalendar = new XMLGregorianCalendarImpl(calendar); return xmlCalendar; }
From source file:org.ambraproject.action.HomePageAction.java
/** * Populate the <b>recentArticles</b> (global) variable with random recent articles of * appropriate Article Type(s).//from w w w . jav a 2s. c om * <ul> * <li>The number of articles set into the <b>recentArticles</b> * (global) variable determined by the * <i>ambra.virtualJournals.CURRENT_JOURNAL_NAME.recentArticles.numArticlesToShow</i> * configuration property * </li> * <li>The type of articles set into the <b>recentArticles</b> variable is determined by * the list in the * <i>ambra.virtualJournals.CURRENT_JOURNAL_NAME.recentArticles.typeUriListArticlesToShow</i> * configuration property. * If this property is not defined, then <b>all</b> types of articles are shown * </li> * <li>The initial definition of "recent" is the number of days (before today) indicated by * the <i>ambra.virtualJournals.CURRENT_JOURNAL_NAME.recentArticles.numDaysInPast</i> * configuration property. * If not enough articles of the appropriate type are found in that span of time, * then a new query is made for a somewhat longer duration. * </li> * </ul> * The CURRENT_JOURNAL_NAME is acquired from the {@link BaseActionSupport#getCurrentJournal()} */ private void initRecentArticles() { String journalKey = getCurrentJournal(); String rootKey = "ambra.virtualJournals." + journalKey + ".recentArticles"; List<URI> typeUriArticlesToShow = getArticleTypesToShow(rootKey); numDaysInPast = configuration.getInteger(rootKey + ".numDaysInPast", 7); numArticlesToShow = configuration.getInteger(rootKey + ".numArticlesToShow", 5); // This is the most recent midnight. No need to futz about with exact dates. Calendar startDate = Calendar.getInstance(); startDate.set(Calendar.HOUR_OF_DAY, 0); startDate.set(Calendar.MINUTE, 0); startDate.set(Calendar.SECOND, 0); startDate.set(Calendar.MILLISECOND, 0); // First query. Just get the articles from "numDaysInPast" ago. Calendar endDate = (Calendar) startDate.clone(); startDate.add(Calendar.DATE, -(numDaysInPast) + 1); BrowseParameters params = new BrowseParameters(); params.setStartDate(startDate); params.setEndDate(endDate); params.setArticleTypes(typeUriArticlesToShow); params.setPageNum(0); params.setPageSize(numArticlesToShow * 100); params.setJournalKey(this.getCurrentJournal()); BrowseResult results = browseService.getArticlesByDate(params); //Create a clone here so we're not modifying the object that is actually in the cache recentArticles = (ArrayList<SearchHit>) results.getArticles().clone(); // If not enough, then query for articles before "numDaysInPast" to make up the difference. if (recentArticles.size() < numArticlesToShow) { endDate = (Calendar) startDate.clone(); endDate.add(Calendar.SECOND, -1); // So no overlap with the first query. startDate.add(Calendar.DATE, -(numDaysInPast) - 1); // One extra day to play it safe. params = new BrowseParameters(); params.setStartDate(startDate); params.setEndDate(endDate); params.setArticleTypes(typeUriArticlesToShow); params.setPageNum(0); params.setPageSize(numArticlesToShow - recentArticles.size()); params.setJournalKey(this.getCurrentJournal()); recentArticles.addAll(browseService.getArticlesByDate(params).getArticles()); } // Now choose a random selection of numArticlesToShow articles from the article pool. // Even if we do not have enough articles, this will still randomize their order. if (recentArticles.size() > 0) { Random randomNumberGenerator = new Random((new Date()).getTime()); // Seed: time = "now". ArrayList<SearchHit> recentArticlesTemp = new ArrayList<SearchHit>(); while (recentArticlesTemp.size() < numArticlesToShow && recentArticles.size() > 0) { // Remove one random article from "recentArticles" and add it to "recentArticlesTemp". int randomNumber = randomNumberGenerator.nextInt(recentArticles.size()); recentArticlesTemp.add(recentArticles.get(randomNumber)); recentArticles.remove(randomNumber); } recentArticles = recentArticlesTemp; } }
From source file:com.annuletconsulting.homecommand.node.AsyncSend.java
/** * Creates the timestamp to be used in signing the JSON request. * /*ww w.j a v a 2 s. co m*/ * @return */ private String getTimestamp() { Calendar today = Calendar.getInstance(); StringBuffer out = new StringBuffer(); out.append(today.get(Calendar.YEAR)); out.append(today.get(Calendar.MONTH) + 1); out.append(today.get(Calendar.DATE)); out.append(today.get(Calendar.HOUR_OF_DAY)); out.append(today.get(Calendar.MINUTE)); out.append(today.get(Calendar.SECOND)); out.append(today.get(Calendar.MILLISECOND)); return out.toString(); }
From source file:com.autentia.intra.bean.activity.GlobalHoursReportBean.java
public float getTotalHours() { ActivitySearch search = new ActivitySearch(); Calendar init = Calendar.getInstance(); init.setTime(startDate);/*from w w w . j a va 2s . c o m*/ Calendar last = Calendar.getInstance(); last.setTime(endDate); init.set(Calendar.HOUR_OF_DAY, init.getMinimum(Calendar.HOUR_OF_DAY)); init.set(Calendar.MINUTE, init.getMinimum(Calendar.MINUTE)); init.set(Calendar.SECOND, init.getMinimum(Calendar.SECOND)); init.set(Calendar.MILLISECOND, init.getMinimum(Calendar.MILLISECOND)); last.set(Calendar.HOUR_OF_DAY, last.getMaximum(Calendar.HOUR_OF_DAY)); last.set(Calendar.MINUTE, last.getMaximum(Calendar.MINUTE)); last.set(Calendar.SECOND, last.getMaximum(Calendar.SECOND)); last.set(Calendar.MILLISECOND, last.getMaximum(Calendar.MILLISECOND)); search.setStartStartDate(init.getTime()); search.setEndStartDate(last.getTime()); if (billable) search.setBillable(true); // Search activities during indicated dates List<Activity> activities = manager.getAllEntities(search, new SortCriteria("role.project.client.name")); // Search for projects in activities and create the global list. float totalHours = 0.0f; for (Activity act : activities) { float horas = act.getDuration() / 60.0f; totalHours = totalHours + horas; } return totalHours; }