List of usage examples for java.util Calendar getTimeInMillis
public long getTimeInMillis()
From source file:erpsystem.chart.Charts.java
/** Grfico criado para mostrar o histrico de * faturamento periodicamente considerando o valor bruto * em R$ de lucro.//from ww w .jav a 2s .co m */ public static BufferedImage create002(int w, int h, Calendar initialCalendar, int interval) { //Inicio DefaultCategoryDataset ds = new DefaultCategoryDataset(); String LUCRO = "Lucro R$"; //Configurando os Calendars. Calendar finalCalendar = getCurrentCalendar(); Calendar finalValue = copyCalendar(initialCalendar); Calendar initialValue = copyCalendar(initialCalendar); while (finalCalendar.after(finalValue)) { //ajustando os Calendars ponteiros. initialValue = copyCalendar(finalValue); finalValue.add(Calendar.DAY_OF_MONTH, interval); //toString para depurao. String s1 = toString(initialValue); String s2 = toString(finalValue); //Obtendo as datas como raw para //possibilitar comparao com o banco de dados. long value1 = initialValue.getTimeInMillis(); long value2 = finalValue.getTimeInMillis(); //Obtendo a nova abstrao de lucro com os intervalos especificados. double lucro = Chart001.getValorLucroEm(value1, value2); double venda = Chart001.getValorVendaEm(value1, value2); double compra = Chart001.getValorCompraEm(value1, value2); //Adicionando a nova abstrao na coleo de dados do grfico. int y = initialValue.get(Calendar.YEAR); int m = initialValue.get(Calendar.MONTH) + 1; int d = initialValue.get(Calendar.DAY_OF_MONTH); String identifier = d + "/" + m + "/" + y; ds.addValue(lucro, "Lucro", identifier); ds.addValue(venda, "Venda", identifier); ds.addValue(compra, "Compra", identifier); } //Criando o grfico abstrato em 3D. JFreeChart chart = ChartFactory.createBarChart3D("Faturamento", "Faturamento", "Valor R$", ds, PlotOrientation.VERTICAL, true, true, false); //Criando e retornando a imagem como //mapa de pixels do grfico. return chart.createBufferedImage(w, h); }
From source file:uk.ac.ox.oucs.vle.TestCourseDAO.java
private static Date createDate(int year, int month, int day) { Calendar cal = Calendar.getInstance(); cal.set(year, month, day);/*from w ww .j a v a2s . c o m*/ return new Date(cal.getTimeInMillis()); }
From source file:dsd.dao.CalculatedDataDAO.java
public static ArrayList<CalculatedData> GetAllForPeriod(Calendar startDate, Calendar endDate, eCalculatedDataType dataType) {//from w w w. ja v a 2s .c om try { Connection con = DAOProvider.getDataSource().getConnection(); ArrayList<CalculatedData> calculatedDataList = new ArrayList<CalculatedData>(); try { String tableName = GetTableNameForDataType(dataType); Object[] parameters = new Object[2]; parameters[0] = new Timestamp(startDate.getTimeInMillis()); parameters[1] = new Timestamp(endDate.getTimeInMillis()); ResultSet results = DAOProvider.SelectTableSecure(tableName, "*", " timestamp >= ? and timestamp <= ? ", "", con, parameters); while (results.next()) { CalculatedData dataTuple = new CalculatedData(); dataTuple.setCalulcatedDataID(results.getLong("ID")); dataTuple.setWindSpeed(results.getFloat(fields[0])); dataTuple.setWindDirection(results.getFloat(fields[1])); dataTuple.setWindSpeedMax(results.getFloat(fields[2])); dataTuple.setWindDirectionMax(results.getFloat(fields[3])); dataTuple.setHydrometer(results.getFloat(fields[4])); dataTuple.setHydrometerVariance(results.getFloat(fields[5])); dataTuple.setSonar(results.getFloat(fields[6])); dataTuple.setSonarVariance(results.getFloat(fields[7])); dataTuple.setSonarPercCorrect(results.getFloat(fields[8])); dataTuple.setSonarPercWrong(results.getFloat(fields[9])); dataTuple.setSonarPercOutOfWater(results.getFloat(fields[10])); dataTuple.setSonarPercError(results.getFloat(fields[11])); dataTuple.setSonarPercUncertain(results.getFloat(fields[12])); dataTuple.setSafetyFactor00(results.getFloat(fields[13])); dataTuple.setSafetyFactor01(results.getFloat(fields[14])); dataTuple.setSafetyFactor10(results.getFloat(fields[15])); dataTuple.setSafetyFactor11(results.getFloat(fields[16])); dataTuple.setWaterSpeed(results.getFloat(fields[17])); dataTuple.setWaterFlowRate(results.getFloat(fields[18])); dataTuple.setTimestamp(results.getTimestamp(fields[19]).getTime()); calculatedDataList.add(dataTuple); } } catch (Exception exc) { exc.printStackTrace(); } con.close(); return calculatedDataList; } catch (Exception exc) { exc.printStackTrace(); } return null; }
From source file:com.cws.esolutions.core.utils.EmailUtils.java
/** * Processes and sends an email message as generated by the requesting * application. This method is utilized with a JNDI datasource. * * @param dataSource - The email message * @param authRequired - <code>true</code> if authentication is required, <code>false</code> otherwise * @param authList - If authRequired is true, this must be populated with the auth info * @return List - The list of email messages in the mailstore * @throws MessagingException {@link javax.mail.MessagingException} if an exception occurs during processing *//* ww w . ja va 2s . co m*/ public static final synchronized List<EmailMessage> readEmailMessages(final Properties dataSource, final boolean authRequired, final List<String> authList) throws MessagingException { final String methodName = EmailUtils.CNAME + "#readEmailMessages(final Properties dataSource, final boolean authRequired, final List<String> authList) throws MessagingException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("dataSource: {}", dataSource); DEBUGGER.debug("authRequired: {}", authRequired); DEBUGGER.debug("authList: {}", authList); } Folder mailFolder = null; Session mailSession = null; Folder archiveFolder = null; List<EmailMessage> emailMessages = null; Calendar cal = Calendar.getInstance(); cal.add(Calendar.HOUR, -24); final Long TIME_PERIOD = cal.getTimeInMillis(); final URLName URL_NAME = (authRequired) ? new URLName(dataSource.getProperty("mailtype"), dataSource.getProperty("host"), Integer.parseInt(dataSource.getProperty("port")), null, authList.get(0), authList.get(1)) : new URLName(dataSource.getProperty("mailtype"), dataSource.getProperty("host"), Integer.parseInt(dataSource.getProperty("port")), null, null, null); if (DEBUG) { DEBUGGER.debug("timePeriod: {}", TIME_PERIOD); DEBUGGER.debug("URL_NAME: {}", URL_NAME); } try { // Set up mail session mailSession = (authRequired) ? Session.getDefaultInstance(dataSource, new SMTPAuthenticator()) : Session.getDefaultInstance(dataSource); if (DEBUG) { DEBUGGER.debug("mailSession: {}", mailSession); } if (mailSession == null) { throw new MessagingException("Unable to configure email services"); } mailSession.setDebug(DEBUG); Store mailStore = mailSession.getStore(URL_NAME); mailStore.connect(); if (DEBUG) { DEBUGGER.debug("mailStore: {}", mailStore); } if (!(mailStore.isConnected())) { throw new MessagingException("Failed to connect to mail service. Cannot continue."); } mailFolder = mailStore.getFolder("inbox"); archiveFolder = mailStore.getFolder("archive"); if (!(mailFolder.exists())) { throw new MessagingException("Requested folder does not exist. Cannot continue."); } mailFolder.open(Folder.READ_WRITE); if ((!(mailFolder.isOpen())) || (!(mailFolder.hasNewMessages()))) { throw new MessagingException("Failed to open requested folder. Cannot continue"); } if (!(archiveFolder.exists())) { archiveFolder.create(Folder.HOLDS_MESSAGES); } Message[] mailMessages = mailFolder.getMessages(); if (mailMessages.length == 0) { throw new MessagingException("No messages were found in the provided store."); } emailMessages = new ArrayList<EmailMessage>(); for (Message message : mailMessages) { if (DEBUG) { DEBUGGER.debug("MailMessage: {}", message); } // validate the message here String messageId = message.getHeader("Message-ID")[0]; Long messageDate = message.getReceivedDate().getTime(); if (DEBUG) { DEBUGGER.debug("messageId: {}", messageId); DEBUGGER.debug("messageDate: {}", messageDate); } // only get emails for the last 24 hours // this should prevent us from pulling too // many emails if (messageDate >= TIME_PERIOD) { // process it Multipart attachment = (Multipart) message.getContent(); Map<String, InputStream> attachmentList = new HashMap<String, InputStream>(); for (int x = 0; x < attachment.getCount(); x++) { BodyPart bodyPart = attachment.getBodyPart(x); if (!(Part.ATTACHMENT.equalsIgnoreCase(bodyPart.getDisposition()))) { continue; } attachmentList.put(bodyPart.getFileName(), bodyPart.getInputStream()); } List<String> toList = new ArrayList<String>(); List<String> ccList = new ArrayList<String>(); List<String> bccList = new ArrayList<String>(); List<String> fromList = new ArrayList<String>(); for (Address from : message.getFrom()) { fromList.add(from.toString()); } if ((message.getRecipients(RecipientType.TO) != null) && (message.getRecipients(RecipientType.TO).length != 0)) { for (Address to : message.getRecipients(RecipientType.TO)) { toList.add(to.toString()); } } if ((message.getRecipients(RecipientType.CC) != null) && (message.getRecipients(RecipientType.CC).length != 0)) { for (Address cc : message.getRecipients(RecipientType.CC)) { ccList.add(cc.toString()); } } if ((message.getRecipients(RecipientType.BCC) != null) && (message.getRecipients(RecipientType.BCC).length != 0)) { for (Address bcc : message.getRecipients(RecipientType.BCC)) { bccList.add(bcc.toString()); } } EmailMessage emailMessage = new EmailMessage(); emailMessage.setMessageTo(toList); emailMessage.setMessageCC(ccList); emailMessage.setMessageBCC(bccList); emailMessage.setEmailAddr(fromList); emailMessage.setMessageAttachments(attachmentList); emailMessage.setMessageDate(message.getSentDate()); emailMessage.setMessageSubject(message.getSubject()); emailMessage.setMessageBody(message.getContent().toString()); emailMessage.setMessageSources(message.getHeader("Received")); if (DEBUG) { DEBUGGER.debug("emailMessage: {}", emailMessage); } emailMessages.add(emailMessage); if (DEBUG) { DEBUGGER.debug("emailMessages: {}", emailMessages); } } // archive it archiveFolder.open(Folder.READ_WRITE); if (archiveFolder.isOpen()) { mailFolder.copyMessages(new Message[] { message }, archiveFolder); message.setFlag(Flags.Flag.DELETED, true); } } } catch (IOException iox) { throw new MessagingException(iox.getMessage(), iox); } catch (MessagingException mex) { throw new MessagingException(mex.getMessage(), mex); } finally { try { if ((mailFolder != null) && (mailFolder.isOpen())) { mailFolder.close(true); } if ((archiveFolder != null) && (archiveFolder.isOpen())) { archiveFolder.close(false); } } catch (MessagingException mx) { ERROR_RECORDER.error(mx.getMessage(), mx); } } return emailMessages; }
From source file:bobs.is.compress.sevenzip.SevenZArchiveEntry.java
/** * Converts NTFS time (100 nanosecond units since 1 January 1601) * to Java time.//www .ja v a2 s .c om * @param ntfsTime the NTFS time in 100 nanosecond units * @return the Java time */ public static Date ntfsTimeToJavaTime(final long ntfsTime) { final Calendar ntfsEpoch = Calendar.getInstance(); ntfsEpoch.setTimeZone(TimeZone.getTimeZone("GMT+0")); ntfsEpoch.set(1601, 0, 1, 0, 0, 0); ntfsEpoch.set(Calendar.MILLISECOND, 0); final long realTime = ntfsEpoch.getTimeInMillis() + (ntfsTime / (10 * 1000)); return new Date(realTime); }
From source file:bobs.is.compress.sevenzip.SevenZArchiveEntry.java
/** * Converts Java time to NTFS time.//from w ww.j a v a 2 s . c om * @param date the Java time * @return the NTFS time */ public static long javaTimeToNtfsTime(final Date date) { final Calendar ntfsEpoch = Calendar.getInstance(); ntfsEpoch.setTimeZone(TimeZone.getTimeZone("GMT+0")); ntfsEpoch.set(1601, 0, 1, 0, 0, 0); ntfsEpoch.set(Calendar.MILLISECOND, 0); return ((date.getTime() - ntfsEpoch.getTimeInMillis()) * 1000 * 10); }
From source file:com.lm.lic.manager.util.GenUtil.java
public static Timestamp timeNowPlusDaysAhead(int daysAhead) { Calendar cal = Calendar.getInstance(); int numDays = daysAhead + cal.get(Calendar.DAY_OF_YEAR); cal.set(Calendar.DAY_OF_YEAR, numDays); Timestamp ts = new Timestamp(cal.getTimeInMillis()); return ts;/*from ww w. ja v a2 s . c o m*/ }
From source file:com.esri.cordova.geolocation.utils.JSONHelper.java
/** * Parses data from PhoneStateListener.LISTEN_CELL_LOCATION.onCellLocationChanged * http://developer.android.com/reference/android/telephony/cdma/CdmaCellLocation.html * @param location GsmCellLocation/*from w w w. j av a2 s . c o m*/ * @return JSON */ public static String gsmCellLocationJSON(GsmCellLocation location) { final Calendar calendar = Calendar.getInstance(); final JSONObject json = new JSONObject(); if (location != null) { try { json.put("provider", CELLLOCATION_PROVIDER); json.put("type", GSM); json.put("timestamp", calendar.getTimeInMillis()); json.put("cid", location.getCid()); json.put("lac", location.getLac()); json.put("psc", location.getPsc()); } catch (JSONException exc) { logJSONException(exc); } } return json.toString(); }
From source file:com.glaf.core.util.DateUtils.java
public static Timestamp removeTime(Timestamp ts) { Calendar cal = Calendar.getInstance(); cal.setTime(ts);// ww w. j a va 2s . c o m cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return new Timestamp(cal.getTimeInMillis()); }
From source file:de.cismet.cids.custom.utils.berechtigungspruefung.BerechtigungspruefungHandler.java
/** * DOCUMENT ME!/* ww w . j a v a 2s. c o m*/ * * @return DOCUMENT ME! */ public static Date getThresholdAnhangDate() { final Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.MONTH, -1); final Date threshold = new Date(calendar.getTimeInMillis()); return threshold; }