List of usage examples for java.util Calendar setTimeInMillis
public void setTimeInMillis(long millis)
From source file:com.antsdb.saltedfish.sql.vdm.FuncDateFormat.java
private String format(String format, Timestamp time) { StringBuilder buf = new StringBuilder(); for (int i = 0; i < format.length(); i++) { char ch = format.charAt(i); if (ch != '%') { buf.append(ch);/*w w w. j a v a 2 s . c om*/ continue; } if (i >= (format.length() - 1)) { buf.append(ch); continue; } char specifier = format.charAt(++i); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(time.getTime()); if (specifier == 'a') { throw new NotImplementedException(); } else if (specifier == 'b') { throw new NotImplementedException(); } else if (specifier == 'c') { buf.append(calendar.get(Calendar.MONTH + 1)); } else if (specifier == 'd') { int day = calendar.get(Calendar.DAY_OF_MONTH); if (day < 10) { buf.append('0'); } buf.append(day); } else if (specifier == 'D') { throw new NotImplementedException(); } else if (specifier == 'e') { buf.append(calendar.get(Calendar.DAY_OF_MONTH)); } else if (specifier == 'f') { buf.append(calendar.get(Calendar.MILLISECOND * 1000)); } else if (specifier == 'H') { buf.append(calendar.get(Calendar.HOUR)); } else if (specifier == 'h') { buf.append(calendar.get(Calendar.HOUR) % 13); } else if (specifier == 'i') { buf.append(calendar.get(Calendar.MINUTE)); } else if (specifier == 'I') { buf.append(calendar.get(Calendar.HOUR) % 13); } else if (specifier == 'j') { buf.append(calendar.get(Calendar.DAY_OF_YEAR)); } else if (specifier == 'k') { buf.append(calendar.get(Calendar.HOUR)); } else if (specifier == 'l') { buf.append(calendar.get(Calendar.HOUR) % 13); } else if (specifier == 'm') { int month = calendar.get(Calendar.MONTH) + 1; if (month < 10) { buf.append('0'); } buf.append(calendar.get(Calendar.MONTH) + 1); } else if (specifier == 'M') { buf.append(calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault())); } else if (specifier == 'p') { int hour = calendar.get(Calendar.HOUR); buf.append(hour < 12 ? "AM" : "PM"); } else if (specifier == 'r') { int hour = calendar.get(Calendar.HOUR); hour = hour % 13; if (hour < 10) { buf.append('0'); } buf.append(hour); buf.append(':'); int minute = calendar.get(Calendar.MINUTE); if (minute < 10) { buf.append('0'); } buf.append(minute); buf.append(':'); int second = calendar.get(Calendar.SECOND); if (second < 10) { buf.append('0'); } buf.append(second); buf.append(hour < 12 ? " AM" : " PM"); } else if (specifier == 's') { buf.append(calendar.get(Calendar.SECOND)); } else if (specifier == 'S') { buf.append(calendar.get(Calendar.SECOND)); } else if (specifier == 'T') { throw new NotImplementedException(); } else if (specifier == 'u') { buf.append(calendar.get(Calendar.WEEK_OF_YEAR)); } else if (specifier == 'U') { throw new NotImplementedException(); } else if (specifier == 'v') { throw new NotImplementedException(); } else if (specifier == 'V') { throw new NotImplementedException(); } else if (specifier == 'w') { throw new NotImplementedException(); } else if (specifier == 'W') { throw new NotImplementedException(); } else if (specifier == 'x') { throw new NotImplementedException(); } else if (specifier == 'X') { throw new NotImplementedException(); } else if (specifier == 'y') { buf.append(calendar.get(Calendar.YEAR) % 100); } else if (specifier == 'Y') { buf.append(calendar.get(Calendar.YEAR)); } else if (specifier == '%') { buf.append('%'); } else { buf.append(specifier); } } return buf.toString(); }
From source file:info.raack.appliancedetection.evaluation.web.EvaluationController.java
@RequestMapping(value = "/evaluation/{id}", method = RequestMethod.GET) public void getEvaluationData(@PathVariable("id") String simulationId, @RequestParam("algorithmId") int algorithmId, @RequestParam(value = "start", required = false) Double startMillis, @RequestParam(value = "end", required = false) Double endMillis, @RequestParam(value = "ticks", required = false) Integer ticks, HttpServletRequest request, HttpServletResponse response) throws IOException { // TODO - for now, just use the naive algorithm's energy measurements. Date start = null;//from www .j av a 2s.c o m Date end = null; if (startMillis != null && endMillis != null) { start = new Date(startMillis.longValue()); end = new Date(endMillis.longValue()); } else if (startMillis != null && endMillis == null) { // if only start or end are provided, create a one day span Calendar c = new GregorianCalendar(); c.setTimeInMillis(startMillis.longValue()); start = c.getTime(); } else if (startMillis == null && endMillis != null) { // if only start or end are provided, create a one day span Calendar c = new GregorianCalendar(); c.setTimeInMillis(endMillis.longValue()); end = c.getTime(); } if (ticks == null) { ticks = 300; } Evaluation evaluation = simulationService.getEvaluation(algorithmId, simulationId, start, end, true); if (evaluation == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } EvaluationWrapper wrapper = new EvaluationWrapper(evaluation); JsonSerializer<EnergyTimestep> dateSerializer = new JsonSerializer<EnergyTimestep>() { // serialize date to milliseconds since epoch public JsonElement serialize(EnergyTimestep energyTimestep, Type me, JsonSerializationContext arg2) { JsonArray object = new JsonArray(); object.add(new JsonPrimitive(energyTimestep.getStartTime().getTime())); object.add(new JsonPrimitive(energyTimestep.getEnergyConsumed())); return object; } }; String dataJS = new GsonBuilder().registerTypeAdapter(EnergyTimestep.class, dateSerializer) .excludeFieldsWithModifiers(Modifier.STATIC).setExclusionStrategies(new ExclusionStrategy() { // skip logger public boolean shouldSkipClass(Class<?> clazz) { return clazz.equals(Logger.class); } public boolean shouldSkipField(FieldAttributes fieldAttributes) { // skip simulation of simulated appliance return (fieldAttributes.getName().equals("simulation") && fieldAttributes.getDeclaringClass() == SimulatedAppliance.class) || // skip simulation second data (fieldAttributes.getName().equals("secondData") && fieldAttributes.getDeclaringClass() == Simulation.class) || // skip endTime of energytimestep (fieldAttributes.getName().equals("endTime") && fieldAttributes.getDeclaringClass() == EnergyTimestep.class) || // skip userAppliance, detectionAlgorithmId of appliance state transition ((fieldAttributes.getName().equals("userAppliance") || fieldAttributes.getName().equals("detectionAlgorithmId")) && fieldAttributes.getDeclaringClass() == ApplianceStateTransition.class); } }).create().toJson(wrapper); response.getWriter().write(dataJS); response.setContentType("application/json"); }
From source file:control.ProcesoVertimientosServlets.SeleccionarFechasVisita.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//from w ww.j a v a 2 s. co m * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { //Parametros que envia el plugin jQuery FullCalendar, estos son enviados en formato TimeStamp String start = request.getParameter("start"); String end = request.getParameter("end"); String clase = request.getParameter("clase"); int codigoProceso = Integer.parseInt(request.getParameter("codigoProceso")); JSONArray jsonArray = new JSONArray(); Calendar fechaInicial = GregorianCalendar.getInstance(); Calendar fechaFinal = GregorianCalendar.getInstance(); /*Se transforaman las fechas de TimeStamp a Calendar*/ fechaInicial.setTimeInMillis((Long.parseLong(start) * 1000)); fechaFinal.setTimeInMillis((Long.parseLong(end) * 1000)); start = fechaInicial.get(GregorianCalendar.DAY_OF_MONTH) + "/" + (fechaInicial.get(GregorianCalendar.MONTH) + 1) + "/" + fechaInicial.get(GregorianCalendar.YEAR); end = fechaFinal.get(GregorianCalendar.DAY_OF_MONTH) + "/" + (fechaFinal.get(GregorianCalendar.MONTH) + 1) + "/" + fechaFinal.get(GregorianCalendar.YEAR); Visitas manager = new Visitas(); jsonArray = manager.getFechasVisitasPorProceso(codigoProceso, start, end, clase); //Armamos la respuesta JSON y la enviamos response.setContentType("application/json"); for (Object jsonObject : jsonArray) { response.getWriter().write(jsonObject.toString()); } } catch (SQLException ex) { // Logger.getLogger(SeleccionarFechasVisitas.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:immf.growl.GrowlApiClient.java
private synchronized void setResetDate(long value) { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(value * 1000); this.resetTime = cal; }
From source file:com.eryansky.common.utils.DateUtil.java
/** * ??//from w w w . j av a2 s .com */ public static long addMinutes(long longCalendar, int intMin) { try { // long longDate = 0; Calendar cal = getCalendar(longCalendar); long longMills = cal.getTimeInMillis() + intMin * 60 * 1000; cal.setTimeInMillis(longMills); if (String.valueOf(longCalendar).length() < 14) longDate = getLongCalendar(cal); else longDate = getLongTime(cal); // return longDate; } catch (Exception Exp) { return -1; } }
From source file:com.infinities.nova.volumes.api.DaseinVolumesApi.java
/** * @param volume/* w w w. j a v a 2s. co m*/ * @param iterable * @return */ private Volume toVolume(org.dasein.cloud.compute.Volume volume, Iterable<VolumeProduct> iterable) { final Volume ret = new Volume(); ret.setAvailabilityZone(volume.getProviderDataCenterId()); Calendar createdAt = Calendar.getInstance(); createdAt.setTimeInMillis(volume.getCreationTimestamp()); ret.setCreatedAt(createdAt); ret.setDescription(volume.getDescription()); ret.setId(volume.getProviderVolumeId()); ret.setMetadata(volume.getTags()); ret.setName(volume.getName()); ret.setSize(volume.getSizeInGigabytes()); ret.setSnapshotId(volume.getProviderSnapshotId()); ret.setStatus(volume.getCurrentState().name()); ret.setVolumeType(volume.getProviderProductId()); try { VolumeProduct product = Iterables.find(iterable, new Predicate<VolumeProduct>() { @Override public boolean apply(VolumeProduct input) { return input.getProviderProductId().equals(ret.getVolumeType()); } }); ret.setVolumeType(product.getName()); } catch (NoSuchElementException e) { ret.setVolumeType(null); // ignore } List<VolumeAttachment> attachments = new ArrayList<VolumeAttachment>(); if (!Strings.isNullOrEmpty(volume.getProviderVirtualMachineId()) && !Strings.isNullOrEmpty(volume.getDeviceId())) { VolumeAttachment attachment = new VolumeAttachment(); attachment.setId(volume.getProviderVolumeId()); attachment.setDevice(volume.getDeviceId()); attachment.setVolumeId(volume.getProviderVolumeId()); attachment.setServerId(volume.getProviderVirtualMachineId()); attachments.add(attachment); } ret.setAttachments(attachments); return ret; }
From source file:com.eryansky.common.utils.DateUtil.java
/** * ???/*from w w w . ja va 2 s. c o m*/ */ public static long addHours(long longCalendar, int intHour) { try { // long longDate = 0; Calendar cal = getCalendar(longCalendar); long longMills = cal.getTimeInMillis() + intHour * 60 * 60 * 1000; cal.setTimeInMillis(longMills); if (String.valueOf(longCalendar).length() < 14) longDate = getLongCalendar(cal); else longDate = getLongTime(cal); // return longDate; } catch (Exception Exp) { return -1; } }
From source file:net.grappendorf.doitlater.TaskEditorActivity.java
public void onDueDatePopup(@SuppressWarnings("unused") View source) { final Calendar cal = Calendar.getInstance(); if (task.getDue() != null) { cal.setTimeInMillis(task.getDue().getValue()); }/*from w w w. j av a 2 s . c om*/ new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker datePicker, int year, int month, int day) { cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month); cal.set(Calendar.DAY_OF_MONTH, day); dueDate.setText(DoItLaterApplication.formatDate(cal.getTime())); } }, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH)).show(); }
From source file:com.eryansky.common.utils.DateUtil.java
/** * ??// ww w .java 2 s . c o m */ public static long addDays(long longCalendar, int intDay) { try { // long longDate = 0; Calendar cal = getCalendar(longCalendar); long longMills = cal.getTimeInMillis() + intDay * 24 * 60 * 60 * 1000; cal.setTimeInMillis(longMills); if (String.valueOf(longCalendar).length() < 14) longDate = getLongCalendar(cal); else longDate = getLongTime(cal); // return longDate; } catch (Exception Exp) { return -1; } }
From source file:com.eryansky.common.utils.DateUtil.java
/** * ??// w w w . ja va 2 s. c o m */ public static long addWeeks(long longCalendar, int intWeek) { try { // long longDate = 0; Calendar cal = getCalendar(longCalendar); long longMills = cal.getTimeInMillis() + intWeek * 7 * 24 * 60 * 60 * 1000; cal.setTimeInMillis(longMills); if (String.valueOf(longCalendar).length() < 14) longDate = getLongCalendar(cal); else longDate = getLongTime(cal); // return longDate; } catch (Exception Exp) { return -1; } }