List of usage examples for java.util Calendar SECOND
int SECOND
To view the source code for java.util Calendar SECOND.
Click Source Link
get
and set
indicating the second within the minute. From source file:com.watchrabbit.crawler.manager.policy.BasicRevisitPolicy.java
@Override public Date getNextExecutionDate(double importance) { int secondsBonus = (int) importance * 1000; Calendar now = clock.getCalendar(); now.add(Calendar.SECOND, maximumIntervalBetweenCrawls); now.add(Calendar.SECOND, -secondsBonus); Date nextExecution = now.getTime(); if (getNextMinimumDate().after(nextExecution)) { nextExecution = getNextMinimumDate(); }// w ww. jav a2 s .c om return new Date(nextExecution.getTime() + random.nextInt(distributionFactor) * 1000); }
From source file:Main.java
/** * Sets the seconds field to a date returning a new object. * The original date object is unchanged. * * @param date the date, not null// www . j av a 2s.c om * @param amount the amount to set * @return a new Date object set with the specified value * @throws IllegalArgumentException if the date is null * @since 2.4 */ public static Date setSeconds(Date date, int amount) { return set(date, Calendar.SECOND, amount); }
From source file:net.seratch.taskun.util.CalendarUtil.java
public static Calendar getCalendar(String yyyy, String mm, String dd) { Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, Integer.valueOf(yyyy)); cal.set(Calendar.MONTH, Integer.valueOf(mm) - 1); cal.set(Calendar.DATE, Integer.valueOf(dd)); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0);/*from w w w . ja va2 s . c om*/ cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return cal; }
From source file:com.liusoft.dlog4j.util.DateUtils.java
/** * ??//w w w . j av a2 s. c om * @param year * @param month * @param date * @return */ public static Calendar getDateBegin(int year, int month, int date) { Calendar begin_time = Calendar.getInstance(); begin_time.set(Calendar.YEAR, year); begin_time.set(Calendar.MONTH, month - 1); begin_time.set(Calendar.DATE, date); begin_time.set(Calendar.HOUR_OF_DAY, 0); begin_time.set(Calendar.MINUTE, 0); begin_time.set(Calendar.SECOND, 0); begin_time.set(Calendar.MILLISECOND, 0); return begin_time; }
From source file:Main.java
/** * Add date time with one minute./* w w w . java 2 s .com*/ * * @param listing the listing * @param currentTime the current time * @param isPast true/false if past time */ private static void addDateTimeWithOneMinute(final List<Long> listing, final long currentTime, final boolean isPast) { final Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(currentTime); if (isPast) { calendar.add(Calendar.MINUTE, -1); } else { calendar.add(Calendar.SECOND, 62); } listing.add(calendar.getTimeInMillis()); }
From source file:co.mafiagame.engine.util.PurgeTimer.java
@PostConstruct public void initPurgeTimer() { Calendar now = Calendar.getInstance(); now.add(Calendar.SECOND, 10); now.add(Calendar.DATE, 1);/*from w ww. j a v a 2 s .c om*/ now.set(Calendar.HOUR_OF_DAY, 6); Timer timer = new Timer(); timer.schedule(this, now.getTime(), 24 * 60 * 60 * 1000); }
From source file:com.livinglogic.ul4.FunctionAsJSON.java
private static void call(StringBuilder builder, Object obj) { if (obj == null) builder.append("null"); else if (obj instanceof Boolean) builder.append(((Boolean) obj).booleanValue() ? "true" : "false"); else if (obj instanceof Integer || obj instanceof Byte || obj instanceof Short || obj instanceof Long || obj instanceof BigInteger || obj instanceof Double || obj instanceof Float) builder.append(obj.toString());//from w w w. j a v a 2 s . co m else if (obj instanceof BigDecimal) { String result = obj.toString(); builder.append(result); if (result.indexOf('.') < 0 || result.indexOf('E') < 0 || result.indexOf('e') < 0) builder.append(".0"); } else if (obj instanceof String) builder.append("\"") // We're using StringEscapeUtils.escapeJava() here, which is the same as escapeJavaScript, except that it doesn't escape ' (which is illegal in JSON strings according to json.org) .append(StringEscapeUtils.escapeJava(((String) obj))).append("\""); else if (obj instanceof Date) { Calendar calendar = new GregorianCalendar(); calendar.setTime((Date) obj); builder.append("new Date(").append(calendar.get(Calendar.YEAR)).append(", ") .append(calendar.get(Calendar.MONTH)).append(", ").append(calendar.get(Calendar.DAY_OF_MONTH)) .append(", ").append(calendar.get(Calendar.HOUR_OF_DAY)).append(", ") .append(calendar.get(Calendar.MINUTE)).append(", ").append(calendar.get(Calendar.SECOND)); int milliSeconds = calendar.get(Calendar.MILLISECOND); if (milliSeconds != 0) { builder.append(", ").append(milliSeconds); } builder.append(")"); } else if (obj instanceof InterpretedTemplate) { builder.append("ul4.Template.loads(\"") .append(StringEscapeUtils.escapeJavaScript(((InterpretedTemplate) obj).dumps())).append("\")"); } else if (obj instanceof TemplateClosure) { builder.append("ul4.Template.loads(\"") .append(StringEscapeUtils.escapeJavaScript(((TemplateClosure) obj).getTemplate().dumps())) .append("\")"); } else if (obj instanceof UL4Attributes) { builder.append("{"); boolean first = true; Set<String> attributeNames = ((UL4Attributes) obj).getAttributeNamesUL4(); for (String attributeName : attributeNames) { if (first) first = false; else builder.append(", "); call(builder, attributeName); builder.append(": "); Object value = ((UL4Attributes) obj).getItemStringUL4(attributeName); call(builder, value); } builder.append("}"); } else if (obj instanceof Color) { Color c = (Color) obj; builder.append("ul4.Color.create(").append(c.getR()).append(", ").append(c.getG()).append(", ") .append(c.getB()).append(", ").append(c.getA()).append(")"); } else if (obj instanceof Collection) { builder.append("["); boolean first = true; for (Object o : (Collection) obj) { if (first) first = false; else builder.append(", "); call(builder, o); } builder.append("]"); } else if (obj instanceof Object[]) { builder.append("["); boolean first = true; for (Object o : (Object[]) obj) { if (first) first = false; else builder.append(", "); call(builder, o); } builder.append("]"); } else if (obj instanceof Map) { builder.append("{"); boolean first = true; Set<Map.Entry> entrySet = ((Map) obj).entrySet(); for (Map.Entry entry : entrySet) { if (first) first = false; else builder.append(", "); call(builder, entry.getKey()); builder.append(": "); call(builder, entry.getValue()); } builder.append("}"); } }
From source file:com.clican.pluto.dataprocess.engine.processes.TimerProcesssorTestCase.java
public void test() throws Exception { taskScheduler.start();//from ww w .jav a2s . co m TimerProcessor p = new TimerProcessor(); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); Date start = DateUtils.add(new Date(), Calendar.SECOND, 3); Date end = DateUtils.add(start, Calendar.SECOND, 3); p.setStartTime(sdf.format(start)); p.setEndTime(sdf.format(end)); p.setCronExpression("* * * * * ?"); p.setConcurrent(true); p.setTaskScheduler(taskScheduler); p.setDataProcessTransaction(dataProcessTransaction); List<DataProcessor> timerProcessors = new ArrayList<DataProcessor>(); final DataProcessor dp = context.mock(DataProcessor.class); timerProcessors.add(dp); p.setTimerProcessors(timerProcessors); final ProcessorContext ctx = new ProcessorContextImpl(); context.checking(new Expectations() { { atLeast(2).of(dp).beforeProcess(ctx); atLeast(2).of(dp).process(ctx); atLeast(2).of(dp).afterProcess(ctx); } }); p.process(ctx); taskScheduler.shutdown(); }
From source file:com.ar.dev.tierra.api.service.FacturaService.java
public Page getFacturasDay(Integer page, Integer size, int idSucursal) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); Date fromDate = calendar.getTime(); calendar.set(Calendar.HOUR_OF_DAY, 23); calendar.set(Calendar.MINUTE, 59); calendar.set(Calendar.SECOND, 59); Date toDate = calendar.getTime(); Page facturas = facturaRepository.findFacturasByDate(fromDate, toDate, new PageRequest(page, size), idSucursal);/*from w w w . j av a2 s . c o m*/ return facturas; }
From source file:DateParser.java
private static Calendar getCalendar(String isodate) { // YYYY-MM-DDThh:mm:ss.sTZD StringTokenizer st = new StringTokenizer(isodate, "-T:.+Z", true); Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC")); calendar.clear();//from ww w. j a v a 2s . co m try { // Year if (st.hasMoreTokens()) { int year = Integer.parseInt(st.nextToken()); calendar.set(Calendar.YEAR, year); } else { return calendar; } // Month if (check(st, "-") && (st.hasMoreTokens())) { int month = Integer.parseInt(st.nextToken()) - 1; calendar.set(Calendar.MONTH, month); } else { return calendar; } // Day if (check(st, "-") && (st.hasMoreTokens())) { int day = Integer.parseInt(st.nextToken()); calendar.set(Calendar.DAY_OF_MONTH, day); } else { return calendar; } // Hour if (check(st, "T") && (st.hasMoreTokens())) { int hour = Integer.parseInt(st.nextToken()); calendar.set(Calendar.HOUR_OF_DAY, hour); } else { calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); return calendar; } // Minutes if (check(st, ":") && (st.hasMoreTokens())) { int minutes = Integer.parseInt(st.nextToken()); calendar.set(Calendar.MINUTE, minutes); } else { calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); return calendar; } // // Not mandatory now // // Secondes if (!st.hasMoreTokens()) { return calendar; } String tok = st.nextToken(); if (tok.equals(":")) { // secondes if (st.hasMoreTokens()) { int secondes = Integer.parseInt(st.nextToken()); calendar.set(Calendar.SECOND, secondes); if (!st.hasMoreTokens()) { return calendar; } // frac sec tok = st.nextToken(); if (tok.equals(".")) { // bug fixed, thx to Martin Bottcher String nt = st.nextToken(); while (nt.length() < 3) { nt += "0"; } nt = nt.substring(0, 3); // Cut trailing chars.. int millisec = Integer.parseInt(nt); // int millisec = Integer.parseInt(st.nextToken()) * 10; calendar.set(Calendar.MILLISECOND, millisec); if (!st.hasMoreTokens()) { return calendar; } tok = st.nextToken(); } else { calendar.set(Calendar.MILLISECOND, 0); } } else { throw new RuntimeException("No secondes specified"); } } else { calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); } // Timezone if (!tok.equals("Z")) { // UTC if (!(tok.equals("+") || tok.equals("-"))) { throw new RuntimeException("only Z, + or - allowed"); } boolean plus = tok.equals("+"); if (!st.hasMoreTokens()) { throw new RuntimeException("Missing hour field"); } int tzhour = Integer.parseInt(st.nextToken()); int tzmin = 0; if (check(st, ":") && (st.hasMoreTokens())) { tzmin = Integer.parseInt(st.nextToken()); } else { throw new RuntimeException("Missing minute field"); } if (plus) { calendar.add(Calendar.HOUR, -tzhour); calendar.add(Calendar.MINUTE, -tzmin); } else { calendar.add(Calendar.HOUR, tzhour); calendar.add(Calendar.MINUTE, tzmin); } } } catch (NumberFormatException ex) { throw new RuntimeException("[" + ex.getMessage() + "] is not an integer"); } return calendar; }