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.silverpeas.jcrutil.RandomGenerator.java
public static Calendar getFuturCalendar() { Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DAY_OF_MONTH, 1 + random.nextInt(10)); 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);//www. j a v a 2 s . co m try { calendar.getTime(); } catch (IllegalArgumentException ie) { return getFuturCalendar(); } return calendar; }
From source file:com.adobe.acs.commons.http.headers.impl.WeeklyExpiresHeaderFilterTest.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. com 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:info.raack.appliancedetection.common.util.DateUtils.java
public Calendar getNextFiveMinuteIncrement(Calendar calOrig) { Calendar cal = (Calendar) calOrig.clone(); // round start time to 5 minute marker to greatly simplify evaluation cal.add(Calendar.MILLISECOND, -1 * cal.get(Calendar.MILLISECOND)); cal.add(Calendar.SECOND, -1 * cal.get(Calendar.SECOND)); cal.add(Calendar.MINUTE, 5 + -1 * cal.get(Calendar.MINUTE) % 5); return cal;//from ww w .ja v a2s .co m }
From source file:Time.java
public int getMilliSeconds() { return calendar_.get(Calendar.MILLISECOND); }
From source file:com.espertech.esper.schedule.ScheduleComputeHelper.java
private static long compute(ScheduleSpec spec, long afterTimeInMillis) { while (true) { Calendar after;/*from w w w . ja v a2 s . c o m*/ if (spec.getOptionalTimeZone() != null) { after = Calendar.getInstance(TimeZone.getTimeZone(spec.getOptionalTimeZone())); } else { after = Calendar.getInstance(); } after.setTimeInMillis(afterTimeInMillis); ScheduleCalendar result = new ScheduleCalendar(); result.setMilliseconds(after.get(Calendar.MILLISECOND)); SortedSet<Integer> minutesSet = spec.getUnitValues().get(ScheduleUnit.MINUTES); SortedSet<Integer> hoursSet = spec.getUnitValues().get(ScheduleUnit.HOURS); SortedSet<Integer> monthsSet = spec.getUnitValues().get(ScheduleUnit.MONTHS); SortedSet<Integer> secondsSet = null; boolean isSecondsSpecified = false; if (spec.getUnitValues().containsKey(ScheduleUnit.SECONDS)) { isSecondsSpecified = true; secondsSet = spec.getUnitValues().get(ScheduleUnit.SECONDS); } if (isSecondsSpecified) { result.setSecond(nextValue(secondsSet, after.get(Calendar.SECOND))); if (result.getSecond() == -1) { result.setSecond(nextValue(secondsSet, 0)); after.add(Calendar.MINUTE, 1); } } result.setMinute(nextValue(minutesSet, after.get(Calendar.MINUTE))); if (result.getMinute() != after.get(Calendar.MINUTE)) { result.setSecond(nextValue(secondsSet, 0)); } if (result.getMinute() == -1) { result.setMinute(nextValue(minutesSet, 0)); after.add(Calendar.HOUR_OF_DAY, 1); } result.setHour(nextValue(hoursSet, after.get(Calendar.HOUR_OF_DAY))); if (result.getHour() != after.get(Calendar.HOUR_OF_DAY)) { result.setSecond(nextValue(secondsSet, 0)); result.setMinute(nextValue(minutesSet, 0)); } if (result.getHour() == -1) { result.setHour(nextValue(hoursSet, 0)); after.add(Calendar.DAY_OF_MONTH, 1); } // This call may change second, minute and/or hour parameters // They may be reset to minimum values if the day rolled result.setDayOfMonth(determineDayOfMonth(spec, after, result)); boolean dayMatchRealDate = false; while (!dayMatchRealDate) { if (checkDayValidInMonth(result.getDayOfMonth(), after.get(Calendar.MONTH), after.get(Calendar.YEAR))) { dayMatchRealDate = true; } else { after.add(Calendar.MONTH, 1); } } int currentMonth = after.get(Calendar.MONTH) + 1; result.setMonth(nextValue(monthsSet, currentMonth)); if (result.getMonth() != currentMonth) { result.setSecond(nextValue(secondsSet, 0)); result.setMinute(nextValue(minutesSet, 0)); result.setHour(nextValue(hoursSet, 0)); result.setDayOfMonth(determineDayOfMonth(spec, after, result)); } if (result.getMonth() == -1) { result.setMonth(nextValue(monthsSet, 0)); after.add(Calendar.YEAR, 1); } // Perform a last valid date check, if failing, try to compute a new date based on this altered after date int year = after.get(Calendar.YEAR); if (!(checkDayValidInMonth(result.getDayOfMonth(), result.getMonth() - 1, year))) { afterTimeInMillis = after.getTimeInMillis(); continue; } return getTime(result, after.get(Calendar.YEAR), spec.getOptionalTimeZone()); } }
From source file:no.met.jtimeseries.marinogram.MarinogramWrapper.java
private static Date getStartDate() { Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); cal.setTime(new Date()); cal.set(Calendar.MINUTE, 0);/* w w w . j av a 2 s . com*/ cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); int startHour = 3; int offset = (startHour - (cal.get(Calendar.HOUR) % startHour)); cal.add(Calendar.HOUR, offset); System.out.println(cal.getTime() + " - " + offset); return cal.getTime(); }
From source file:com.zergiu.tvman.jobs.TestTVRageShowLoader.java
/** * Test method for {@link com.zergiu.tvman.shows.tvrage.TVRageShowLoaderJob#execute(org.quartz.JobExecutionContext)}. * @throws JobExecutionException /* w w w. j av a2 s . com*/ */ @Test public void testExecuteBuffyTheVampireSlayer() throws JobExecutionException { context.checking(new Expectations() { { oneOf(jobContext).getJobDetail(); will(returnValue(jobDetail)); } }); context.checking(new Expectations() { { oneOf(jobDetail).getJobBuilder(); will(returnValue(JobBuilder.newJob())); } }); show.setProviderSeriesId("2930"); showLoader = createShowLoader("resources/tvrage/buffy_full_show_info.xml"); showLoader.execute(jobContext); context.assertIsSatisfied(); assertNotNull(show.getSeasons()); assertEquals(7, show.getSeasons().size()); assertEquals(144, getEpisodeCount()); assertEquals(TVShowStatus.Ended, show.getStatus()); Calendar firstAirDate = Calendar.getInstance(); firstAirDate.set(Calendar.YEAR, 1997); firstAirDate.set(Calendar.MONTH, Calendar.MARCH); firstAirDate.set(Calendar.DAY_OF_MONTH, 10); firstAirDate.set(Calendar.HOUR_OF_DAY, 0); firstAirDate.set(Calendar.MINUTE, 0); firstAirDate.set(Calendar.SECOND, 0); firstAirDate.set(Calendar.MILLISECOND, 0); assertEquals(firstAirDate.getTime(), show.getFirstAirDate()); for (TVShowSeason season : show.getSeasons()) { for (TVShowEpisode ep : season.getEpisodes()) { assertNotNull(ep.getAirDate()); } } }
From source file:lineage2.gameserver.network.telnet.commands.TelnetServer.java
/** * Constructor for TelnetServer.// ww w . ja v a 2s . c om */ public TelnetServer() { _commands.add(new TelnetCommand("version", "ver") { @Override public String getUsage() { return "version"; } @Override public String handle(String[] args) { return "Rev." + GameServer.getInstance().getVersion().getRevisionNumber() + " Builded : " + GameServer.getInstance().getVersion().getBuildDate() + "\n"; } }); _commands.add(new TelnetCommand("uptime") { @Override public String getUsage() { return "uptime"; } @Override public String handle(String[] args) { return DurationFormatUtils.formatDurationHMS(ManagementFactory.getRuntimeMXBean().getUptime()) + "\n"; } }); _commands.add(new TelnetCommand("restart") { @Override public String getUsage() { return "restart <seconds>|now>"; } @Override public String handle(String[] args) { if (args.length == 0) { return null; } StringBuilder sb = new StringBuilder(); if (NumberUtils.isNumber(args[0])) { int val = NumberUtils.toInt(args[0]); Shutdown.getInstance().schedule(val, Shutdown.RESTART); sb.append("Server will restart in ").append(Shutdown.getInstance().getSeconds()) .append(" seconds!\n"); sb.append("Type \"abort\" to abort restart!\n"); } else if (args[0].equalsIgnoreCase("now")) { sb.append("Server will restart now!\n"); Shutdown.getInstance().schedule(0, Shutdown.RESTART); } else { String[] hhmm = args[0].split(":"); Calendar date = Calendar.getInstance(); Calendar now = Calendar.getInstance(); date.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hhmm[0])); date.set(Calendar.MINUTE, hhmm.length > 1 ? Integer.parseInt(hhmm[1]) : 0); date.set(Calendar.SECOND, 0); date.set(Calendar.MILLISECOND, 0); if (date.before(now)) { date.roll(Calendar.DAY_OF_MONTH, true); } int seconds = (int) ((date.getTimeInMillis() / 1000L) - (now.getTimeInMillis() / 1000L)); Shutdown.getInstance().schedule(seconds, Shutdown.RESTART); sb.append("Server will restart in ").append(Shutdown.getInstance().getSeconds()) .append(" seconds!\n"); sb.append("Type \"abort\" to abort restart!\n"); } return sb.toString(); } }); _commands.add(new TelnetCommand("shutdown") { @Override public String getUsage() { return "shutdown <seconds>|now|<hh:mm>"; } @Override public String handle(String[] args) { if (args.length == 0) { return null; } StringBuilder sb = new StringBuilder(); if (NumberUtils.isNumber(args[0])) { int val = NumberUtils.toInt(args[0]); Shutdown.getInstance().schedule(val, Shutdown.SHUTDOWN); sb.append("Server will shutdown in ").append(Shutdown.getInstance().getSeconds()) .append(" seconds!\n"); sb.append("Type \"abort\" to abort shutdown!\n"); } else if (args[0].equalsIgnoreCase("now")) { sb.append("Server will shutdown now!\n"); Shutdown.getInstance().schedule(0, Shutdown.SHUTDOWN); } else { String[] hhmm = args[0].split(":"); Calendar date = Calendar.getInstance(); Calendar now = Calendar.getInstance(); date.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hhmm[0])); date.set(Calendar.MINUTE, hhmm.length > 1 ? Integer.parseInt(hhmm[1]) : 0); date.set(Calendar.SECOND, 0); date.set(Calendar.MILLISECOND, 0); if (date.before(now)) { date.roll(Calendar.DAY_OF_MONTH, true); } int seconds = (int) ((date.getTimeInMillis() / 1000L) - (now.getTimeInMillis() / 1000L)); Shutdown.getInstance().schedule(seconds, Shutdown.SHUTDOWN); sb.append("Server will shutdown in ").append(Shutdown.getInstance().getSeconds()) .append(" seconds!\n"); sb.append("Type \"abort\" to abort shutdown!\n"); } return sb.toString(); } }); _commands.add(new TelnetCommand("abort") { @Override public String getUsage() { return "abort"; } @Override public String handle(String[] args) { Shutdown.getInstance().cancel(); return "Aborted.\n"; } }); }
From source file:com.autentia.intra.bean.activity.GlobalHoursReportBean.java
public List<GlobalHourReport> getAll() { // Retrieve activities for every User during that period of time ActivitySearch search = new ActivitySearch(); Calendar init = Calendar.getInstance(); init.setTime(startDate);//from w ww . j av a2 s. 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()); List<GlobalHourReport> listGlobal = new ArrayList<GlobalHourReport>(); 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. for (Activity act : activities) { Project proj = act.getRole().getProject(); GlobalHourReport unit = new GlobalHourReport(); unit.setProject(proj); // an entry in the list represents a project if (!listGlobal.contains(unit)) listGlobal.add(unit); // Retrieve the stored unit and save hours GlobalHourReport storedUnit = listGlobal.get(listGlobal.indexOf(unit)); float horas = act.getDuration() / 60.0f; storedUnit.setUserHours(act.getUser(), horas); storedUnit.setIterator(usuarios.iterator()); } return listGlobal; }
From source file:hd3gtv.mydmam.pathindexing.ImporterCDFinder.java
protected long doIndex(IndexingEvent elementpush) throws IOException { BufferedReader reader = new BufferedReader( new InputStreamReader(new BufferedInputStream(new FileInputStream(filetoimport)))); String line;//from w ww. j a v a 2 s .c om String[] cols; SourcePathIndexerElement element; Calendar date = Calendar.getInstance(); int count = 0; String[] partpath; String current_rootpath = null; long last_valid_date = 0; while ((line = reader.readLine()) != null) { try { line = line.trim(); if (line.equals("")) { continue; } cols = line.split("\t"); if (cols.length != 6) { continue; } element = new SourcePathIndexerElement(); element.currentpath = "/" + cols[1].replaceAll(":", "/"); element.parentpath = element.currentpath.substring(0, element.currentpath.lastIndexOf("/")); if (element.parentpath.equals("")) { element.parentpath = "/"; } if (cols[4].equals("dossier") | cols[4].equals("Dossier d'archive Zip")) { element.directory = true; } else { element.id = MyDMAM.getIdFromFilename(cols[0]); element.directory = false; } if (cols[3].equals("n.a.") == false) { try { date.set(Calendar.YEAR, Integer.valueOf(cols[3].substring(0, 4))); date.set(Calendar.MONTH, Integer.valueOf(cols[3].substring(5, 7)) - 1); date.set(Calendar.DAY_OF_MONTH, Integer.valueOf(cols[3].substring(8, 10))); date.set(Calendar.HOUR_OF_DAY, Integer.valueOf(cols[3].substring(11, 13))); date.set(Calendar.MINUTE, Integer.valueOf(cols[3].substring(14, 16))); date.set(Calendar.SECOND, Integer.valueOf(cols[3].substring(17, 19))); date.set(Calendar.MILLISECOND, 0); element.date = date.getTimeInMillis(); last_valid_date = element.date; } catch (Exception e) { Log2Dump dump = new Log2Dump(); dump.add("cols[1]", cols[1]); dump.add("cols[3]", cols[3]); Log2.log.error("CDFinder date analyser", e, dump); } } element.storagename = poolname; element.dateindex = System.currentTimeMillis(); elementpush.onFoundElement(element); partpath = element.currentpath.split("/"); if (partpath.length == 3) { if (current_rootpath == null) { current_rootpath = "/" + partpath[1]; element = new SourcePathIndexerElement(); element.currentpath = current_rootpath; element.dateindex = System.currentTimeMillis(); element.directory = true; element.parentpath = "/"; element.storagename = poolname; element.date = last_valid_date; elementpush.onFoundElement(element); } else { if (current_rootpath.equals("/" + partpath[1]) == false) { current_rootpath = "/" + partpath[1]; element = new SourcePathIndexerElement(); element.currentpath = current_rootpath; element.dateindex = System.currentTimeMillis(); element.directory = true; element.parentpath = "/"; element.storagename = poolname; element.date = last_valid_date; elementpush.onFoundElement(element); } } } } catch (Exception e) { reader.close(); throw new IOException("Can't process found element", e.getCause()); } count++; } reader.close(); try { elementpush.onFoundElement(SourcePathIndexerElement.prepareStorageElement(poolname)); } catch (Exception e) { Log2.log.error("Can't push to ES root storage", e); } return count; }