List of usage examples for java.util Calendar setTimeInMillis
public void setTimeInMillis(long millis)
From source file:org.openmrs.module.appointmentscheduling.web.controller.AppointmentBlockCalendarController.java
@RequestMapping(method = RequestMethod.POST) public String loadForm(HttpServletRequest request, ModelMap model, @RequestParam(value = "action", required = false) String action, @RequestParam(value = "locationId", required = false) Location location, @RequestParam(value = "chosenType", required = false) Integer appointmentTypeId, @RequestParam(value = "chosenProvider", required = false) Integer providerId, @RequestParam(value = "fromDate", required = false) Long fromDate, @RequestParam(value = "toDate", required = false) Long toDate, @RequestParam(value = "appointmentBlockId", required = false) Integer appointmentBlockId) { if (Context.isAuthenticated()) { //Updating session variables Calendar cal = OpenmrsUtil.getDateTimeFormat(Context.getLocale()).getCalendar(); cal.setTimeInMillis(fromDate); Date fromDateAsDate = cal.getTime(); cal.setTimeInMillis(toDate);/*w w w . ja v a2 s . c o m*/ Date toDateAsDate = cal.getTime(); HttpSession httpSession = request.getSession(); httpSession.setAttribute("chosenLocation", location); httpSession.setAttribute("lastLocale", Context.getLocale()); httpSession.setAttribute("chosenProvider", providerId); httpSession.setAttribute("chosenType", appointmentTypeId); //If the user wants to add new appointment block (clicked on a day) if (action != null && action.equals("addNewAppointmentBlock")) { String getRequest = ""; //Fill the request from the user with selected date and forward it to appointmentBlockForm getRequest += "fromDate=" + Context.getDateTimeFormat().format(fromDateAsDate); if (toDate != null && !toDate.equals(fromDate)) { //If the fromDate is not the same as toDate (not a day click on month view) getRequest += "&toDate=" + Context.getDateTimeFormat().format(toDateAsDate); } getRequest += "&redirectedFrom=appointmentBlockCalendar.list"; return "redirect:appointmentBlockForm.form?" + getRequest; } //If the user wants to change the view to table view else if (action != null && action.equals("changeToTableView")) { return "redirect:appointmentBlockList.list"; } //If the user wants to edit an existing appointment block (clicked on an event) else if (action != null && action.equals("editAppointmentBlock")) { return "redirect:appointmentBlockForm.form?appointmentBlockId=" + appointmentBlockId + "&redirectedFrom=appointmentBlockCalendar.list"; } } return null; }
From source file:ec.com.ebos.web.master.jsf.bean.TechnicalInfo.java
public void initialize() { try {/*from ww w . ja va 2 s. com*/ ResourceBundle rb = ResourceBundle.getBundle(Constantes.DOMAIN_NAME + ".admin.resources.ebosconfig"); String strAppProps = rb.getString("application.properties"); int lastBrace = strAppProps.indexOf("}"); strAppProps = strAppProps.substring(1, lastBrace); Map<String, String> appProperties = new HashMap<String, String>(); String[] appProps = strAppProps.split("[\\s,]+"); for (String appProp : appProps) { String[] keyValue = appProp.split("="); if (keyValue != null && keyValue.length > 1) { appProperties.put(keyValue[0], keyValue[1]); } } version = appProperties.get("ebos.version"); spring = "Spring: " + appProperties.get("spring.version"); hibernate = "Hibernate: " + appProperties.get("hibernate.version"); primeFaces = "PrimeFaces: " + appProperties.get("primefaces.version"); primeFacesExt = "PrimeFaces Extensions: " + appProperties.get("primefaces-extensions.version"); jsfImpl = "JSF: " + appProperties.get("jsf-impl") + " " + appProperties.get("jsfVersion"); server = "Server: " + ((ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext()) .getServerInfo(); DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm"); Calendar calendar = Calendar.getInstance(); if (appProperties.containsKey("timestamp")) { calendar.setTimeInMillis(Long.valueOf(appProperties.get("timestamp"))); } buildTime = "Build time: " + formatter.format(calendar.getTime()); mojarra = appProperties.get("jsf-impl").contains("mojarra"); //mfenoglio process new and updated components this.proccessNewsComponents(appProperties.get("primefaces-extensions.new-components"), appProperties.get("primefaces-extensions.updated-components")); } catch (MissingResourceException e) { LOGGER.warning("Resource bundle 'ebosconfig' was not found"); } }
From source file:com.appeligo.search.actions.ResponseReportAction.java
public String execute() throws Exception { long timestamp = new Date().getTime(); String day = Utils.getDatePath(timestamp); String hostname = null;/* ww w .j a v a 2s . c o m*/ try { hostname = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { hostname = "UnknownHost"; } String dirname = documentRoot + "/stats/" + day + "/" + hostname; String responseFileName = dirname + "/response-" + reporter + ".html"; try { File dir = new File(dirname); if ((!dir.exists()) && (!dir.mkdirs())) { throw new IOException("Error creating directory " + dirname); } File file = new File(responseFileName); PrintStream responseFile = null; if (file.exists()) { responseFile = new PrintStream(new FileOutputStream(responseFileName, true)); } else { responseFile = new PrintStream(new FileOutputStream(responseFileName)); String title = "Response Times for " + getServletRequest().getServerName() + " to " + reporter; responseFile.println("<html><head><title>" + title + "</title></head>"); responseFile.println("<body><h1>" + title + "</h1>"); responseFile.println("<table border='1'>"); responseFile.println("<tr>"); responseFile.println("<th>Time (UTC)</th>"); responseFile.println("<th>Response (Millis)</th>"); responseFile.println("<th>Status</th>"); responseFile.println("<th>Bytes Read</th>"); responseFile.println("<th>Timed Out</th>"); responseFile.println("<th>Exception</th>"); responseFile.println("</tr>"); } Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("GMT")); cal.setTimeInMillis(timestamp); String time = String.format("%1$tH:%1$tM:%1$tS", cal); responseFile.print("<tr>"); responseFile.print("<td>" + time + "</td>"); responseFile.format("<td>%,d</td>", responseMillis); responseFile.print("<td>" + status + "</td>"); responseFile.format("<td>%,d</td>", bytesRead); responseFile.print("<td>" + timedOut + "</td>"); responseFile.print("<td>" + exception + "</td>"); responseFile.println("</tr>"); } catch (IOException e) { log.error("Error opening or writing to " + responseFileName, e); } return SUCCESS; }
From source file:net.sf.l2j.gameserver.instancemanager.clanhallsiege.FortressofTheDeadManager.java
private FortressofTheDeadManager() { _log.info("Fortress of The Dead"); long siegeDate = restoreSiegeDate(64); Calendar tmpDate = Calendar.getInstance(); tmpDate.setTimeInMillis(siegeDate); setSiegeDate(tmpDate);/*from w w w. j a va2s. c om*/ setNewSiegeDate(siegeDate, 64, 22); _clansDamageInfo = new HashMap<Integer, DamageInfo>(); // Schedule siege auto start _startSiegeTask.schedule(1000); }
From source file:com.hichinaschool.flashcards.libanki.Utils.java
public static void printDate(String name, double date) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss"); df.setTimeZone(TimeZone.getTimeZone("GMT")); Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT")); cal.setTimeInMillis((long) date * 1000); // Log.d(AnkiDroidApp.TAG, "Value of " + name + ": " + cal.getTime().toGMTString()); }
From source file:com.hichinaschool.flashcards.libanki.Utils.java
/** * Returns the effective date of the present moment. * If the time is prior the cut-off time (9:00am by default as of 11/02/10) return yesterday, * otherwise today/*from w w w . j a v a 2s . c o m*/ * Note that the Date class is java.sql.Date whose constructor sets hours, minutes etc to zero * * @param utcOffset The UTC offset in seconds we are going to use to determine today or yesterday. * @return The date (with time set to 00:00:00) that corresponds to today in Anki terms */ public static Date genToday(double utcOffset) { // The result is not adjusted for timezone anymore, following libanki model // Timezone adjustment happens explicitly in Deck.updateCutoff(), but not in Deck.checkDailyStats() SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); df.setTimeZone(TimeZone.getTimeZone("GMT")); Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT")); cal.setTimeInMillis(System.currentTimeMillis() - (long) utcOffset * 1000l); Date today = Date.valueOf(df.format(cal.getTime())); return today; }
From source file:com.heliumv.api.machine.MachineApi.java
@GET @Path("/planningview") public PlanningView getPlanningView(@QueryParam(Param.USERID) String userId, @QueryParam("dateMs") Long dateMs, @QueryParam("days") Integer days, @QueryParam(Param.LIMIT) Integer limit, @QueryParam(Param.STARTINDEX) Integer startIndex, @QueryParam(Filter.HIDDEN) Boolean filterWithHidden, @QueryParam("filter_startdate") Boolean filterStartDate, @QueryParam(With.DESCRIPTION) Boolean withDescription) throws RemoteException, NamingException, EJBExceptionLP { PlanningView planningView = new PlanningView(); if (connectClient(userId) == null) return planningView; planningView.setMachineList(getMachinesImpl(limit, startIndex, filterWithHidden)); if (filterStartDate == null) { filterStartDate = new Boolean(false); }/*from w w w. ja v a 2s.com*/ if (dateMs == null) { dateMs = new Long(System.currentTimeMillis()); } if (days == null) { days = new Integer(1); } Calendar c = Calendar.getInstance(); c.setTimeInMillis(dateMs); c.add(Calendar.DAY_OF_YEAR, days); long endDateMs = c.getTimeInMillis(); planningView.setOpenWorkList(productionApi.getOpenWorkEntriesImpl(limit, startIndex, filterStartDate ? dateMs : null, endDateMs)); planningView.setMachineGroupList(getMachineGroupsImpl(limit, startIndex)); Map<Integer, MachineAvailabilityEntryList> mapAvailability = new HashMap<Integer, MachineAvailabilityEntryList>(); for (MachineEntry machine : planningView.getMachineList().getEntries()) { mapAvailability.put(machine.getId(), getAvailabilitiesImpl(machine.getId(), dateMs, days, withDescription)); } planningView.setMachineAvailabilityMap(mapAvailability); return planningView; }
From source file:iphonestalker.util.FindMyIPhoneReader.java
private IPhoneLocation getLocation(JSONObject object) { IPhoneLocation iPhoneLocation = null; // Get location information JSONObject location = (JSONObject) object.get("location"); if (location != null) { boolean locationFinished = (Boolean) location.get("locationFinished"); if (locationFinished) { long timestamp = (Long) location.get("timeStamp"); Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(timestamp); //System.out.println("positionType: " + location.get("positionType")); double horizontalAccuracy = (Double) location.get("horizontalAccuracy"); //System.out.println("locationFinished: " + location.get("locationFinished")); double latitude = (Double) location.get("latitude"); double longitude = (Double) location.get("longitude"); //System.out.println("isOld: " + location.get("isOld")); DecimalFormat df = new DecimalFormat("#.0000"); iPhoneLocation = new IPhoneLocation(Double.parseDouble(df.format(latitude)), Double.parseDouble(df.format(longitude))); iPhoneLocation.setFulldate(cal.getTime()); iPhoneLocation.setHorizontalAccuracy(horizontalAccuracy); iPhoneLocation.setConfidence(70 - (int) horizontalAccuracy); iPhoneLocation.setHitCount(1); }// ww w.j av a 2 s .c o m } return iPhoneLocation; }
From source file:com.owncloud.android.lib.resources.shares.UpdateRemoteShareOperation.java
@Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = null; int status = -1; /// prepare array of parameters to update List<Pair<String, String>> parametersToUpdate = new ArrayList<Pair<String, String>>(); if (mPassword != null) { parametersToUpdate.add(new Pair<String, String>(PARAM_PASSWORD, mPassword)); }/*from ww w . ja v a 2s . com*/ if (mExpirationDateInMillis < 0) { // clear expiration date parametersToUpdate.add(new Pair(PARAM_EXPIRATION_DATE, "")); } else if (mExpirationDateInMillis > 0) { // set expiration date DateFormat dateFormat = new SimpleDateFormat(FORMAT_EXPIRATION_DATE); Calendar expirationDate = Calendar.getInstance(); expirationDate.setTimeInMillis(mExpirationDateInMillis); String formattedExpirationDate = dateFormat.format(expirationDate.getTime()); parametersToUpdate.add(new Pair(PARAM_EXPIRATION_DATE, formattedExpirationDate)); } // else, ignore - no update /* TODO complete rest of parameters if (mPermissions > 0) { parametersToUpdate.add(new Pair("permissions", Integer.toString(mPermissions))); } if (mPublicUpload != null) { parametersToUpdate.add(new Pair("publicUpload", mPublicUpload.toString()); } */ /// perform required PUT requests PutMethod put = null; String uriString = null; try { Uri requestUri = client.getBaseUri(); Uri.Builder uriBuilder = requestUri.buildUpon(); uriBuilder.appendEncodedPath(ShareUtils.SHARING_API_PATH.substring(1)); uriBuilder.appendEncodedPath(Long.toString(mRemoteId)); uriString = uriBuilder.build().toString(); for (Pair<String, String> parameter : parametersToUpdate) { if (put != null) { put.releaseConnection(); } put = new PutMethod(uriString); put.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); put.setRequestEntity(new StringRequestEntity(parameter.first + "=" + parameter.second, ENTITY_CONTENT_TYPE, ENTITY_CHARSET)); status = client.executeMethod(put); if (status == HttpStatus.SC_OK) { String response = put.getResponseBodyAsString(); // Parse xml response ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( new ShareXMLParser()); parser.setOwnCloudVersion(client.getOwnCloudVersion()); parser.setServerBaseUri(client.getBaseUri()); result = parser.parse(response); } else { result = new RemoteOperationResult(false, status, put.getResponseHeaders()); } } } catch (Exception e) { result = new RemoteOperationResult(e); Log_OC.e(TAG, "Exception while updating remote share ", e); if (put != null) { put.releaseConnection(); } } finally { if (put != null) { put.releaseConnection(); } } return result; }
From source file:desktopsearch.WatchDir.java
private void UpdateDB(String Event, Path FullLocation) throws SQLException, IOException { File file = new File(FullLocation.toString()); String path = file.getParent(); String Name = file.getName(); if (Name.contains("'")) { Name = Name.replace("'", "''"); }//from w w w .j av a2s.c o m if (path.contains("'")) { path = path.replace("'", "''"); } if (Event.equals("ENTRY_CREATE") && file.exists()) { FileTime LastModifiedTime = Files.getLastModifiedTime(FullLocation); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(LastModifiedTime.toMillis()); String Query; if (file.isFile()) { String Type = FilenameUtils.getExtension(FullLocation.toString()); if (Type.endsWith("~") || Type.equals("")) { Type = "Text"; } Query = "INSERT INTO FileInfo VALUES('" + path + "','" + Name + "','" + Type + "','" + calendar.getTime() + "'," + (file.length() / 1024) + ");"; } else if (!Files.isSymbolicLink(FullLocation)) { long size = FileUtils.sizeOfDirectory(file); Query = "INSERT INTO FileInfo VALUES('" + path + "','" + Name + "','FOLDER','" + calendar.getTime() + "'," + size + ");"; } else { Query = "INSERT INTO FileInfo VALUES('" + path + "','" + Name + "','LINK','" + calendar.getTime() + "',0);"; } statement.executeUpdate(Query); } else if (Event.equals("ENTRY_MODIFY")) { System.out.println(path + "/" + Name); FileTime LastModifiedTime = Files.getLastModifiedTime(FullLocation); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(LastModifiedTime.toMillis()); String Query = "UPDATE FileInfo SET LastModified='" + calendar.getTime() + "' WHERE FileLocation='" + path + "' and FileName='" + Name + "';"; System.out.println(Query); statement.executeUpdate(Query); } else if (Event.equals("ENTRY_DELETE")) { String Query = "DELETE FROM FileInfo WHERE FileLocation = '" + path + "' AND FileName = '" + Name + "';"; statement.executeUpdate(Query); } connection.commit(); }