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.indoqa.lang.util.TimeUtilsTest.java
@Test public void parseDate() { Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("GMT+1")); calendar.set(2012, 2, 1, 10, 5, 30); calendar.set(Calendar.MILLISECOND, 501); assertEquals(calendar.getTimeInMillis(), TimeUtils.parseDate("2012-03-01 09:05:30.501").getTime()); }
From source file:helper.lang.DateHelperTest.java
@Test public void testGetRangeDaysBeforeOneDay() { int days = 1; Calendar localtime = Calendar.getInstance(); CalendarRange range = DateHelper.getRangeFullDaysBefore(localtime, days); Calendar start = range.getStart(); Calendar end = range.getEnd(); System.out.println(DateFormatUtils.SMTP_DATETIME_FORMAT.format(start)); System.out.println(DateFormatUtils.SMTP_DATETIME_FORMAT.format(end)); // end date is midnight of date passed in assertEquals(localtime.get(Calendar.YEAR), end.get(Calendar.YEAR)); assertEquals(localtime.get(Calendar.MONTH), end.get(Calendar.MONTH)); assertEquals(localtime.get(Calendar.DATE), end.get(Calendar.DATE)); assertEquals(0, end.get(Calendar.HOUR)); assertEquals(0, end.get(Calendar.MINUTE)); assertEquals(0, end.get(Calendar.SECOND)); assertEquals(0, end.get(Calendar.MILLISECOND)); assertEquals(0, end.get(Calendar.HOUR_OF_DAY)); assertEquals(DateHelper.UTC_TIME_ZONE, end.getTimeZone()); // start date is 11:59:59 or 'days' time localtime.add(Calendar.DATE, -(days + 2)); //-1 is day before, -1 for day before day before, to include day before (> x) assertEquals(localtime.get(Calendar.YEAR), start.get(Calendar.YEAR)); assertEquals(localtime.get(Calendar.MONTH), start.get(Calendar.MONTH)); assertEquals(localtime.get(Calendar.DATE), start.get(Calendar.DATE)); assertEquals(11, start.get(Calendar.HOUR)); assertEquals(23, start.get(Calendar.HOUR_OF_DAY)); assertEquals(59, start.get(Calendar.MINUTE)); assertEquals(59, start.get(Calendar.SECOND)); assertEquals(999, start.get(Calendar.MILLISECOND)); assertEquals(DateHelper.UTC_TIME_ZONE, start.getTimeZone()); }
From source file:org.activiti.rest.service.api.repository.ModelResourceTest.java
public void testDeleteModel() throws Exception { Model model = null;/*from w ww . j av a 2s .co m*/ try { Calendar now = Calendar.getInstance(); now.set(Calendar.MILLISECOND, 0); processEngineConfiguration.getClock().setCurrentTime(now.getTime()); model = repositoryService.newModel(); model.setCategory("Model category"); model.setKey("Model key"); model.setMetaInfo("Model metainfo"); model.setName("Model name"); model.setVersion(2); repositoryService.saveModel(model); HttpDelete httpDelete = new HttpDelete( SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, model.getId())); closeResponse(executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT)); // Check if the model is really gone assertNull(repositoryService.createModelQuery().modelId(model.getId()).singleResult()); model = null; } finally { if (model != null) { try { repositoryService.deleteModel(model.getId()); } catch (Throwable ignore) { // Ignore, model might not be created } } } }
From source file:com.comcast.cats.monitor.reboot.BarcelonaRebootMonitor.java
/** * Calculates the uptime of the box.// w w w .j a v a 2s . c om */ private long calculateUptime(String upTimeDays, String upTimehours) throws ParseException, NumberFormatException { Date actualUptime = DateUtils.parseDate(upTimehours, EXPECTED_DATE_FORMATS); if (upTimeDays != null) { actualUptime = DateUtils.addDays(actualUptime, Integer.parseInt(upTimeDays)); } Calendar cal = Calendar.getInstance(); cal.setTime(actualUptime); cal.getTimeInMillis(); long upTimemillis = (cal.get(Calendar.HOUR_OF_DAY) * 60 * 60 * 1000) + (cal.get(Calendar.MINUTE) * 60 * 1000) + (cal.get(Calendar.SECOND) * 1000) + (cal.get(Calendar.MILLISECOND)); return upTimemillis; }
From source file:com.adobe.acs.commons.http.headers.impl.WeeklyExpiresHeaderFilterTest.java
@Test public void testDoActivateSuccess() throws Exception { properties.put(WeeklyExpiresHeaderFilter.PROP_EXPIRES_DAY_OF_WEEK, Calendar.SUNDAY); Calendar actual = Calendar.getInstance(); actual.set(Calendar.SECOND, 0); actual.set(Calendar.MILLISECOND, 0); actual.set(Calendar.HOUR_OF_DAY, 1); actual.set(Calendar.MINUTE, 29); filter.doActivate(componentContext); filter.adjustExpires(actual);//from w w w . j a v a 2s .c o m assertEquals(Calendar.SUNDAY, actual.get(Calendar.DAY_OF_WEEK)); // Abstract class will pass expires, this checks we aren't messing with the time. assertEquals(1, actual.get(Calendar.HOUR_OF_DAY)); assertEquals(29, actual.get(Calendar.MINUTE)); }
From source file:com.ar.dev.tierra.api.dao.impl.ChartDAOImpl.java
@Override public List<Chart> getMontoMedioPago(int idMedioPago) { Calendar calendarInitial = Calendar.getInstance(); Calendar calendarClosing = Calendar.getInstance(); calendarInitial.set(Calendar.HOUR_OF_DAY, 0); calendarInitial.set(Calendar.MINUTE, 0); calendarInitial.set(Calendar.SECOND, 0); calendarInitial.set(Calendar.MILLISECOND, 0); Date fromDate = calendarInitial.getTime(); calendarClosing.set(Calendar.HOUR_OF_DAY, 23); calendarClosing.set(Calendar.MINUTE, 59); calendarClosing.set(Calendar.SECOND, 59); calendarClosing.set(Calendar.MILLISECOND, 59); Date toDate = calendarClosing.getTime(); int days = 0; List<Chart> chartMedioPago = new ArrayList<>(); while (days <= 6) { Chart chart = new Chart(); Criteria metodo = getSession().createCriteria(MetodoPagoFactura.class); metodo.add(Restrictions.eq("estado", true)); Criteria planPago = metodo.createCriteria("planPago"); Criteria tarjeta = planPago.createCriteria("tarjeta"); Criteria medioPago = tarjeta.createCriteria("medioPago"); medioPago.add(Restrictions.eq("idMedioPago", idMedioPago)); metodo.add(Restrictions.between("fechaCreacion", fromDate, toDate)); metodo.setProjection(Projections.sum("montoPago")); BigDecimal counter = (BigDecimal) metodo.uniqueResult(); if (counter != null) { chart.setValue(counter.intValue()); } else {/*from w w w . j av a 2 s. com*/ chart.setValue(0); } chart.setDate(fromDate); chartMedioPago.add(chart); calendarInitial.add(Calendar.DAY_OF_MONTH, -1); fromDate = calendarInitial.getTime(); calendarClosing.add(Calendar.DAY_OF_MONTH, -1); toDate = calendarClosing.getTime(); days++; } return chartMedioPago; }
From source file:mx.edu.um.mateo.inventario.dao.impl.FacturaAlmacenDaoHibernate.java
@Override @Transactional(readOnly = true)/* ww w . ja va 2s .c o m*/ public Map<String, Object> lista(Map<String, Object> params) { log.debug("Buscando lista de facturas con params {}", params); if (params == null) { params = new HashMap<>(); } if (!params.containsKey("max")) { params.put("max", 10); } else { params.put("max", Math.min((Integer) params.get("max"), 100)); } if (params.containsKey("pagina")) { Long pagina = (Long) params.get("pagina"); Long offset = (pagina - 1) * (Integer) params.get("max"); params.put("offset", offset.intValue()); } if (!params.containsKey("offset")) { params.put("offset", 0); } Criteria criteria = currentSession().createCriteria(FacturaAlmacen.class); Criteria countCriteria = currentSession().createCriteria(FacturaAlmacen.class); if (params.containsKey("almacen")) { criteria.createCriteria("almacen").add(Restrictions.idEq(params.get("almacen"))); countCriteria.createCriteria("almacen").add(Restrictions.idEq(params.get("almacen"))); } if (params.containsKey("fechaIniciado")) { log.debug("Buscando desde {}", params.get("fechaIniciado")); criteria.add(Restrictions.ge("fechaCreacion", params.get("fechaIniciado"))); countCriteria.add(Restrictions.ge("fechaCreacion", params.get("fechaIniciado"))); } else { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_MONTH, 1); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 1); log.debug("Asignando busqueda desde {}", calendar.getTime()); criteria.add(Restrictions.ge("fechaCreacion", calendar.getTime())); countCriteria.add(Restrictions.ge("fechaCreacion", calendar.getTime())); } if (params.containsKey("fechaTerminado")) { log.debug("Buscando hasta {}", params.get("fechaTerminado")); criteria.add(Restrictions.le("fechaCreacion", params.get("fechaTerminado"))); countCriteria.add(Restrictions.le("fechaCreacion", params.get("fechaTerminado"))); } if (params.containsKey("filtro")) { String filtro = (String) params.get("filtro"); Disjunction propiedades = Restrictions.disjunction(); propiedades.add(Restrictions.ilike("folio", filtro, MatchMode.ANYWHERE)); criteria.add(propiedades); countCriteria.add(propiedades); } if (params.containsKey("order")) { String campo = (String) params.get("order"); if (params.get("sort").equals("desc")) { criteria.addOrder(Order.desc(campo)); } else { criteria.addOrder(Order.asc(campo)); } } else { criteria.createCriteria("estatus").addOrder(Order.asc("prioridad")); } criteria.addOrder(Order.desc("fechaModificacion")); if (!params.containsKey("reporte")) { criteria.setFirstResult((Integer) params.get("offset")); criteria.setMaxResults((Integer) params.get("max")); } params.put("facturas", criteria.list()); countCriteria.setProjection(Projections.rowCount()); params.put("cantidad", (Long) countCriteria.list().get(0)); return params; }
From source file:com.ligadata.kamanja.consumer.Main.java
private static void startScheduledTasks() { Calendar alertsAggCal = Calendar.getInstance(); alertsAggCal.add(Calendar.MILLISECOND, START_SCHEDULED_TASK_AFTER); Timer timer = new Timer(); timer.schedule(new AlertsAggTimerTask(), alertsAggCal.getTime(), config.getLong(ConfigFields.ALERTS_AGG_TASK_PERIOD_MILLIES)); }//from ww w. j av a2 s. c om
From source file:edu.ucsb.nceas.ezid.test.EZIDServiceTest.java
/** Generate a timestamp for use in IDs. */ public static String generateTimeString() { StringBuffer guid = new StringBuffer(); // Create a calendar to get the date formatted properly String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000); SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]); pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); Calendar calendar = new GregorianCalendar(pdt); Date trialTime = new Date(); calendar.setTime(trialTime);// w w w. ja v a 2 s .c o m guid.append(calendar.get(Calendar.YEAR)); guid.append(calendar.get(Calendar.DAY_OF_YEAR)); guid.append(calendar.get(Calendar.HOUR_OF_DAY)); guid.append(calendar.get(Calendar.MINUTE)); guid.append(calendar.get(Calendar.SECOND)); guid.append(calendar.get(Calendar.MILLISECOND)); double random = Math.random(); guid.append(random); return guid.toString(); }
From source file:com.mozilla.bagheera.sink.SequenceFileSink.java
private void initWriter() throws IOException { if (LOG.isDebugEnabled()) { LOG.debug("Thread " + Thread.currentThread().getId() + " - initWriter() called"); }/*from w w w. j a v a 2 s.co m*/ if (!hdfs.exists(baseDir)) { hdfs.mkdirs(baseDir); } outputPath = new Path(baseDir, new Path(UUID.randomUUID().toString())); LOG.info("Opening file handle to: " + outputPath.toString()); if (useBytesValue) { writer = SequenceFile.createWriter(hdfs, conf, outputPath, Text.class, BytesWritable.class, CompressionType.BLOCK); } else { writer = SequenceFile.createWriter(hdfs, conf, outputPath, Text.class, Text.class, CompressionType.BLOCK); } // Get time in millis at a day resolution Calendar prev = Calendar.getInstance(); prev.set(Calendar.HOUR_OF_DAY, 0); prev.set(Calendar.MINUTE, 0); prev.set(Calendar.SECOND, 0); prev.set(Calendar.MILLISECOND, 0); nextRolloverMillis = prev.getTimeInMillis() + DAY_IN_MILLIS; }