List of usage examples for java.util Calendar setTimeInMillis
public void setTimeInMillis(long millis)
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstXMsgClient.CFAstXMsgClientSchema.java
public static Calendar convertTimeString(String val) { if ((val == null) || (val.length() == 0)) { return (null); } else if (val.length() != 8) { throw CFLib.getDefaultExceptionFactory().newUsageException(CFAstXMsgClientSchema.class, "convertTimeString", "Value must be in HH24:MI:SS format, \"" + val + "\" is invalid"); } else if (((val.charAt(0) >= '0') && (val.charAt(0) <= '2')) && ((val.charAt(1) >= '0') && (val.charAt(1) <= '9')) && (val.charAt(2) == ':') && ((val.charAt(3) >= '0') && (val.charAt(3) <= '5')) && ((val.charAt(4) >= '0') && (val.charAt(4) <= '9')) && (val.charAt(5) == ':') && ((val.charAt(6) >= '0') && (val.charAt(6) <= '5')) && ((val.charAt(7) >= '0') && (val.charAt(7) <= '9'))) { /*/*from w w w .jav a2 s . c o m*/ * NOTE: * .Net uses substring( startcol, lengthOfSubstring ) * Java uses substring( startcol, endcol ) and does not * include charAt( endcol ); */ int hour = Integer.parseInt(val.substring(0, 2)); int minute = Integer.parseInt(val.substring(3, 5)); int second = Integer.parseInt(val.substring(6, 8)); Calendar retval = new GregorianCalendar(CFLibDbUtil.getDbServerTimeZone()); retval.set(Calendar.YEAR, 2000); retval.set(Calendar.MONTH, 0); retval.set(Calendar.DAY_OF_MONTH, 1); retval.set(Calendar.HOUR_OF_DAY, hour); retval.set(Calendar.MINUTE, minute); retval.set(Calendar.SECOND, second); Calendar local = new GregorianCalendar(); local.setTimeInMillis(retval.getTimeInMillis()); return (local); } else { throw CFLib.getDefaultExceptionFactory().newUsageException(CFAstXMsgClientSchema.class, "convertTimeString", "Value must be in HH24:MI:SS format \"" + val + "\" is invalid"); } }
From source file:eu.dime.ps.dto.ProfileCard.java
private void addToModel(Model model, URI rUri, URI property, Object value) { if (ArrayUtils.contains(DATETIME_PROPERTIES, property)) { Calendar calendar = Calendar.getInstance(); if (value instanceof Long) { calendar.setTimeInMillis((Long) value); value = calendar;/*w ww. j a v a 2 s. c o m*/ } if (value instanceof Integer) { if (GenericValidator.isLong(value.toString())) { calendar.setTimeInMillis(((Integer) value).longValue()); value = calendar; } } } if (value instanceof String) { Node object = null; try { object = new URIImpl(expand((String) value)); model.addStatement(rUri, property, object); } catch (IllegalArgumentException e) { object = model.createPlainLiteral((String) value); model.addStatement(rUri, property, object); } } else if (CONVERTERS.containsKey(property)) { model.addStatement(rUri, property, CONVERTERS.get(property).toNode(model, value)); } else { model.addStatement(rUri, property, RDFReactorRuntime.java2node(model, value)); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstXMsgClient.CFAstXMsgClientSchema.java
public static Calendar convertDateString(String val) { if ((val == null) || (val.length() == 0)) { return (null); } else if (val.length() != 10) { throw CFLib.getDefaultExceptionFactory().newUsageException(CFAstXMsgClientSchema.class, "convertDateString", "Value must be in YYYY-MM-DD format, \"" + val + "\" is invalid"); } else if (((val.charAt(0) >= '0') && (val.charAt(0) <= '9')) && ((val.charAt(1) >= '0') && (val.charAt(1) <= '9')) && ((val.charAt(2) >= '0') && (val.charAt(2) <= '9')) && ((val.charAt(3) >= '0') && (val.charAt(3) <= '9')) && (val.charAt(4) == '-') && ((val.charAt(5) >= '0') && (val.charAt(5) <= '1')) && ((val.charAt(6) >= '0') && (val.charAt(6) <= '9')) && (val.charAt(7) == '-') && ((val.charAt(8) >= '0') && (val.charAt(8) <= '3')) && ((val.charAt(9) >= '0') && (val.charAt(9) <= '9'))) { /*//www . j a v a2 s. co m * NOTE: * .Net uses substring( startcol, lengthOfSubstring ) * Java uses substring( startcol, endcol ) and does not * include charAt( endcol ); */ int year = Integer.parseInt(val.substring(0, 4)); int month = Integer.parseInt(val.substring(5, 7)); int day = Integer.parseInt(val.substring(8, 10)); Calendar retval = new GregorianCalendar(CFLibDbUtil.getDbServerTimeZone()); retval.set(Calendar.YEAR, year); retval.set(Calendar.MONTH, month - 1); retval.set(Calendar.DAY_OF_MONTH, day); retval.set(Calendar.HOUR_OF_DAY, 0); retval.set(Calendar.MINUTE, 0); retval.set(Calendar.SECOND, 0); Calendar local = new GregorianCalendar(); local.setTimeInMillis(retval.getTimeInMillis()); return (local); } else { throw CFLib.getDefaultExceptionFactory().newUsageException(CFAstXMsgClientSchema.class, "convertDateString", "Value must be in YYYY-MM-DD format, \"" + val + "\" is invalid"); } }
From source file:com.bac.accountserviceapp.data.mysql.MysqlAccountServiceAppAuthenticateAppTest.java
private Date getDateWithoutMillis() { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.set(Calendar.MILLISECOND, 0); return new Date(calendar.getTimeInMillis()); }
From source file:fr.aliasource.webmail.proxy.XmlMailMessageParser.java
private MailMessage parseMessage(Calendar cal, Element me) { String subject = DOMUtils.getElementText(me, "subject"); String messageId = DOMUtils.getElementText(me, "messageId"); MailBody body = parseMailBody(me);/* w ww . jav a2s .c om*/ cal.setTimeInMillis(Long.parseLong(me.getAttribute("date"))); Date d = cal.getTime(); String[][] sender = DOMUtils.getAttributes(me, "from", new String[] { "addr", "displayName" }); Address from = new Address(sender[0][1], sender[0][0]); Element recip = DOMUtils.getUniqueElement(me, "to"); String[][] ra = DOMUtils.getAttributes(recip, "r", new String[] { "addr", "displayName" }); List<Address> to = getAddresses(ra); recip = DOMUtils.getUniqueElement(me, "cc"); ra = DOMUtils.getAttributes(recip, "r", new String[] { "addr", "displayName" }); List<Address> cc = getAddresses(ra); recip = DOMUtils.getUniqueElement(me, "bcc"); ra = DOMUtils.getAttributes(recip, "r", new String[] { "addr", "displayName" }); List<Address> bcc = getAddresses(ra); Element attachements = DOMUtils.getUniqueElement(me, "attachements"); String[][] aIds = DOMUtils.getAttributes(attachements, "a", new String[] { "id" }); Map<String, String> attachs = new HashMap<String, String>(); for (int i = 0; i < aIds.length; i++) { attachs.put(aIds[i][0], ""); } MailMessage cm = new MailMessage(subject, body, attachs, d, from, to, cc, bcc, null, null); cm.setSmtpId(messageId); return cm; }
From source file:com.cerema.cloud2.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)); }// w w w.j ava 2 s . c o m 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 if (mPermissions > 0) { // set permissions parametersToUpdate.add(new Pair(PARAM_PERMISSIONS, Integer.toString(mPermissions))); } if (mPublicUpload != null) { parametersToUpdate.add(new Pair(PARAM_PUBLIC_UPLOAD, Boolean.toString(mPublicUpload))); } /// 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:info.raack.appliancedetection.evaluation.model.Simulation.java
private void setStartTime(long timeInMillis) { Calendar cal = new GregorianCalendar(); cal.setTimeInMillis(timeInMillis); // round start time to 5 minute marker to greatly simplify evaluation cal = dateUtils.getPreviousFiveMinuteIncrement(cal); startTime = cal.getTime();/*from w w w . jav a 2 s .com*/ logger.debug("Setting start time for simulated data to be " + startTime); }
From source file:com.clican.pluto.fsm.engine.impl.JobContextImpl.java
public void loadJobs() { if (!running) { start();//from w w w . j av a 2 s. c om } if (!running || activeThreadCount.longValue() > maxThreadNum) { if (log.isDebugEnabled()) { log.debug("Running=[" + running + "],activeThreadCount=[" + activeThreadCount.longValue() + "],maxThreadNum=[" + maxThreadNum + "] This loading is ignored"); } return; } Calendar current = Calendar.getInstance(); current.setTimeInMillis(current.getTimeInMillis() + refreshTime); List<Job> jobList = jobService.findJobByExecuteTime(current.getTime(), JobStatus.IDLE); if (log.isTraceEnabled()) { log.trace("find " + jobList.size() + " jobs to execute"); } for (Job job : jobList) { job.setStatus(JobStatus.EXECUTING.getStatus()); jobService.updateJob(job); if (log.isDebugEnabled()) { log.debug("find a job [" + job + "] and prepare to execute it"); } executor.submit(getRunnable(job)); } }
From source file:com.orange.oidc.tim.service.TokensKeys.java
String getExpires() { if (expires != null && timems != 0) { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(timems); return "" + cal.get(Calendar.DAY_OF_MONTH) + "/" + cal.get(Calendar.MONTH) + "/" + cal.get(Calendar.YEAR) + " " + cal.get(Calendar.HOUR) + ":" + cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND); } else if (expires != null) { Calendar cal = Calendar.getInstance(); cal = fromStringToDate(expires); if (cal != null) { return "" + cal.get(Calendar.DAY_OF_MONTH) + "/" + cal.get(Calendar.MONTH) + "/" + cal.get(Calendar.YEAR) + " " + cal.get(Calendar.HOUR) + ":" + cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND); }//from ww w . j av a 2s .co m } return ""; }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstXMsgClient.CFAstXMsgClientSchema.java
public static Calendar convertTimestampString(String val) { if ((val == null) || (val.length() == 0)) { return (null); } else if (val.length() != 19) { throw CFLib.getDefaultExceptionFactory().newUsageException(CFAstXMsgClientSchema.class, "convertTimestampString", "Value must be in YYYY-MM-DD HH24:MI:SS format \"" + val + "\" is invalid"); } else if (((val.charAt(0) >= '0') && (val.charAt(0) <= '9')) && ((val.charAt(1) >= '0') && (val.charAt(1) <= '9')) && ((val.charAt(2) >= '0') && (val.charAt(2) <= '9')) && ((val.charAt(3) >= '0') && (val.charAt(3) <= '9')) && (val.charAt(4) == '-') && ((val.charAt(5) >= '0') && (val.charAt(5) <= '1')) && ((val.charAt(6) >= '0') && (val.charAt(6) <= '9')) && (val.charAt(7) == '-') && ((val.charAt(8) >= '0') && (val.charAt(8) <= '3')) && ((val.charAt(9) >= '0') && (val.charAt(9) <= '9')) && (val.charAt(10) == ' ') && ((val.charAt(11) >= '0') && (val.charAt(11) <= '2')) && ((val.charAt(12) >= '0') && (val.charAt(12) <= '9')) && (val.charAt(13) == ':') && ((val.charAt(14) >= '0') && (val.charAt(14) <= '5')) && ((val.charAt(15) >= '0') && (val.charAt(15) <= '9')) && (val.charAt(16) == ':') && ((val.charAt(17) >= '0') && (val.charAt(17) <= '5')) && ((val.charAt(18) >= '0') && (val.charAt(18) <= '9'))) { /*/*from w w w . j a v a 2 s .c o m*/ * NOTE: * .Net uses substring( startcol, lengthOfSubstring ) * Java uses substring( startcol, endcol ) and does not * include charAt( endcol ); */ int year = Integer.parseInt(val.substring(0, 4)); int month = Integer.parseInt(val.substring(5, 7)); int day = Integer.parseInt(val.substring(8, 10)); int hour = Integer.parseInt(val.substring(11, 13)); int minute = Integer.parseInt(val.substring(14, 16)); int second = Integer.parseInt(val.substring(17, 19)); Calendar retval = new GregorianCalendar(CFLibDbUtil.getDbServerTimeZone()); retval.set(Calendar.YEAR, year); retval.set(Calendar.MONTH, month - 1); retval.set(Calendar.DAY_OF_MONTH, day); retval.set(Calendar.HOUR_OF_DAY, hour); retval.set(Calendar.MINUTE, minute); retval.set(Calendar.SECOND, second); Calendar local = new GregorianCalendar(); local.setTimeInMillis(retval.getTimeInMillis()); return (local); } else { throw CFLib.getDefaultExceptionFactory().newUsageException(CFAstXMsgClientSchema.class, "convertTimestampString", "Value must be in YYYY-MM-DD HH24:MI:SS format \"" + val + "\" is invalid"); } }