List of usage examples for java.util Date toString
public String toString()
where:dow mon dd hh:mm:ss zzz yyyy
From source file:org.catechis.Domartin.java
public static String getCurrentFormattedDate() { SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy"); Date date = new Date(); String str_date = date.toString(); ParsePosition pp = new ParsePosition(0); long time = 0; try {/* w ww.ja v a 2 s.c o m*/ date = sdf.parse(str_date, pp); } catch (java.lang.NullPointerException npe) { } str_date = date.toString(); return str_date; }
From source file:com.iitb.cse.ConnectionInfo.java
public static void writeToMyLog(int expid, String macAdrress, String message) { String location = ""; if (!Constants.experimentDetailsDirectory.endsWith("/")) { location = Constants.experimentDetailsDirectory + "/"; }//from w w w. j a v a 2 s. com location += Integer.toString(expid) + macAdrress + "_log.txt"; File file = new File(location); try { FileWriter fw = new FileWriter(file, true); BufferedWriter bw = new BufferedWriter(fw); Date date = new Date(); System.out.println(date); bw.write(date.toString() + " --> " + message + "\n"); bw.close(); } catch (IOException ex) { System.out.println("\nEXCEPTION [writeToMyLog]:" + ex.toString()); } }
From source file:Main.java
public static void writeLifeLogCountInFile(int walking, int running, int vehicle, int bicycle, String filename) throws IOException { Date date = new Date(); BufferedWriter writer = null; File dir = new File(Environment.getExternalStorageDirectory() + "/LifeLog"); Log.d("Directory PATH", dir.getAbsolutePath()); boolean flag = dir.mkdir(); Log.d("Directory created?", "" + flag); File file = new File(dir.getAbsolutePath(), filename); if (file.exists() == false) { file.createNewFile();//ww w . ja v a 2 s . com writer = new BufferedWriter(new FileWriter(file, true)); writer.write("Date,Walking,Running,Bicycle,Vehicle"); writer.newLine(); writer.write(date.toString() + "," + walking + "," + running + "," + bicycle + "," + vehicle); writer.newLine(); } else { writer = new BufferedWriter(new FileWriter(file, true)); writer.write(date.toString() + "," + walking + "," + running + "," + bicycle + "," + vehicle); writer.newLine(); Log.d("Appended", "True"); } writer.flush(); writer.close(); }
From source file:com.eucalyptus.objectstorage.pipeline.handlers.S3Authentication.java
/** * Gets the date for S3-spec authentication * * @param httpRequest//from w ww . j a v a 2 s . c om * @return * @throws com.eucalyptus.objectstorage.exceptions.s3.AccessDeniedException */ static String getDate(MappingHttpRequest httpRequest) throws AccessDeniedException { String date; String verifyDate; if (httpRequest.containsHeader("x-amz-date")) { date = ""; verifyDate = httpRequest.getHeader("x-amz-date"); } else { date = httpRequest.getAndRemoveHeader(SecurityParameter.Date.toString()); verifyDate = date; if (date == null || date.length() <= 0) throw new AccessDeniedException("User authentication failed. Date must be specified."); } try { Date dateToVerify = DateUtil.parseDate(verifyDate); Date currentDate = new Date(); if (Math.abs( currentDate.getTime() - dateToVerify.getTime()) > ObjectStorageProperties.EXPIRATION_LIMIT) { LOG.error("Incoming ObjectStorage message is expired. Current date: " + currentDate.toString() + " Message's Verification Date: " + dateToVerify.toString()); throw new AccessDeniedException("Message expired. Sorry."); } } catch (Exception ex) { LOG.error("Cannot parse date: " + verifyDate); throw new AccessDeniedException("Unable to parse date."); } return date; }
From source file:es.uvigo.darwin.jmodeltest.io.HtmlReporter.java
public static void buildReport(ApplicationOptions options, Model models[], File mOutputFile, TreeSummary summary) {//from w w w.j a v a2 s .com File outputFile; if (mOutputFile != null) { if (!(mOutputFile.getName().endsWith(".htm") || mOutputFile.getName().endsWith(".html"))) { outputFile = new File(mOutputFile.getAbsolutePath() + ".html"); } else { outputFile = mOutputFile; } } else { outputFile = new File(LOG_DIR.getPath() + File.separator + options.getInputFile().getName() + ".jmodeltest." + options.getExecutionName() + ".html"); } // Add the values in the datamodel datamodel = new HashMap<String, Object>(); java.util.Date current_time = new java.util.Date(); datamodel.put("date", current_time.toString()); datamodel.put("system", System.getProperty("os.name") + " " + System.getProperty("os.version") + ", arch: " + System.getProperty("os.arch") + ", bits: " + System.getProperty("sun.arch.data.model") + ", numcores: " + Runtime.getRuntime().availableProcessors()); fillInWithOptions(options); fillInWithSortedModels(models); datamodel.put("isTopologiesSummary", summary != null ? new Integer(1) : new Integer(0)); if (summary != null) { fillInWithTopologies(summary, options); } if (options.doAIC) { Collection<Map<String, String>> aicModels = new ArrayList<Map<String, String>>(); Map<String, String> bestAicModel = new HashMap<String, String>(); fillInWIthInformationCriterion(ModelTest.getMyAIC(), aicModels, bestAicModel); datamodel.put("aicModels", aicModels); datamodel.put("bestAicModel", bestAicModel); datamodel.put("aicConfidenceCount", ModelTest.getMyAIC().getConfidenceModels().size()); StringBuffer aicConfModels = new StringBuffer(); for (Model model : ModelTest.getMyAIC().getConfidenceModels()) aicConfModels.append(model.getName() + " "); datamodel.put("aicConfidenceList", aicConfModels.toString()); if (options.writePAUPblock) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); TextOutputStream strOutput = new TextOutputStream(ps); ModelTest.WritePaupBlock(strOutput, "AIC", ModelTest.getMyAIC().getMinModel()); try { String pblock = baos.toString("UTF8"); pblock = pblock.replaceAll("\n", "<br/>"); datamodel.put("aicPaup", pblock); } catch (UnsupportedEncodingException e) { } } buildChart(outputFile, ModelTest.getMyAIC()); datamodel.put("aicEuImagePath", IMAGES_DIR.getName() + File.separator + outputFile.getName() + "_eu_AIC.png"); datamodel.put("aicRfImagePath", IMAGES_DIR.getName() + File.separator + outputFile.getName() + "_rf_AIC.png"); } if (options.doAICc) { Collection<Map<String, String>> aiccModels = new ArrayList<Map<String, String>>(); Map<String, String> bestAiccModel = new HashMap<String, String>(); fillInWIthInformationCriterion(ModelTest.getMyAICc(), aiccModels, bestAiccModel); datamodel.put("aiccModels", aiccModels); datamodel.put("bestAiccModel", bestAiccModel); datamodel.put("aiccConfidenceCount", ModelTest.getMyAICc().getConfidenceModels().size()); StringBuffer aiccConfModels = new StringBuffer(); for (Model model : ModelTest.getMyAICc().getConfidenceModels()) aiccConfModels.append(model.getName() + " "); datamodel.put("aiccConfidenceList", aiccConfModels.toString()); if (options.writePAUPblock) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); TextOutputStream strOutput = new TextOutputStream(ps); ModelTest.WritePaupBlock(strOutput, "AICc", ModelTest.getMyAICc().getMinModel()); try { String pblock = baos.toString("UTF8"); pblock = pblock.replaceAll("\n", "<br/>"); datamodel.put("aiccPaup", pblock); } catch (UnsupportedEncodingException e) { } } buildChart(outputFile, ModelTest.getMyAICc()); datamodel.put("aiccEuImagePath", IMAGES_DIR.getName() + File.separator + outputFile.getName() + "_eu_AICc.png"); datamodel.put("aiccRfImagePath", IMAGES_DIR.getName() + File.separator + outputFile.getName() + "_rf_AICc.png"); } if (options.doBIC) { Collection<Map<String, String>> bicModels = new ArrayList<Map<String, String>>(); Map<String, String> bestBicModel = new HashMap<String, String>(); fillInWIthInformationCriterion(ModelTest.getMyBIC(), bicModels, bestBicModel); datamodel.put("bicModels", bicModels); datamodel.put("bestBicModel", bestBicModel); datamodel.put("bicConfidenceCount", ModelTest.getMyBIC().getConfidenceModels().size()); StringBuffer bicConfModels = new StringBuffer(); for (Model model : ModelTest.getMyBIC().getConfidenceModels()) bicConfModels.append(model.getName() + " "); datamodel.put("bicConfidenceList", bicConfModels.toString()); if (options.writePAUPblock) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); TextOutputStream strOutput = new TextOutputStream(ps); ModelTest.WritePaupBlock(strOutput, "BIC", ModelTest.getMyBIC().getMinModel()); try { String pblock = baos.toString("UTF8"); pblock = pblock.replaceAll("\n", "<br/>"); datamodel.put("bicPaup", pblock); } catch (UnsupportedEncodingException e) { } } buildChart(outputFile, ModelTest.getMyBIC()); datamodel.put("bicEuImagePath", IMAGES_DIR.getName() + File.separator + outputFile.getName() + "_eu_BIC.png"); datamodel.put("bicRfImagePath", IMAGES_DIR.getName() + File.separator + outputFile.getName() + "_rf_BIC.png"); } if (options.doDT) { Collection<Map<String, String>> dtModels = new ArrayList<Map<String, String>>(); Map<String, String> bestDtModel = new HashMap<String, String>(); fillInWIthInformationCriterion(ModelTest.getMyDT(), dtModels, bestDtModel); datamodel.put("dtModels", dtModels); datamodel.put("bestDtModel", bestDtModel); datamodel.put("dtConfidenceCount", ModelTest.getMyDT().getConfidenceModels().size()); StringBuffer dtConfModels = new StringBuffer(); for (Model model : ModelTest.getMyDT().getConfidenceModels()) dtConfModels.append(model.getName() + " "); datamodel.put("dtConfidenceList", dtConfModels.toString()); if (options.writePAUPblock) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); TextOutputStream strOutput = new TextOutputStream(ps); ModelTest.WritePaupBlock(strOutput, "DT", ModelTest.getMyDT().getMinModel()); try { String pblock = baos.toString("UTF8"); pblock = pblock.replaceAll("\n", "<br/>"); datamodel.put("dtPaup", pblock); } catch (UnsupportedEncodingException e) { } } buildChart(outputFile, ModelTest.getMyDT()); datamodel.put("dtEuImagePath", IMAGES_DIR.getName() + File.separator + outputFile.getName() + "_eu_DT.png"); datamodel.put("dtRfImagePath", IMAGES_DIR.getName() + File.separator + outputFile.getName() + "_rf_DT.png"); } datamodel.put("doAICAveragedPhylogeny", ModelTest.getConsensusAIC() != null ? new Integer(1) : new Integer(0)); if (ModelTest.getConsensusAIC() != null) { datamodel.put("aicConsensusTree", TreeUtilities.toNewick(ModelTest.getConsensusAIC().getConsensus(), true, true, true)); datamodel.put("consensusType", ModelTest.getConsensusAIC().getConsensusType()); } datamodel.put("doAICcAveragedPhylogeny", ModelTest.getConsensusAICc() != null ? new Integer(1) : new Integer(0)); if (ModelTest.getConsensusAICc() != null) { datamodel.put("aiccConsensusTree", TreeUtilities.toNewick(ModelTest.getConsensusAICc().getConsensus(), true, true, true)); datamodel.put("consensusType", ModelTest.getConsensusAICc().getConsensusType()); } datamodel.put("doBICAveragedPhylogeny", ModelTest.getConsensusBIC() != null ? new Integer(1) : new Integer(0)); if (ModelTest.getConsensusBIC() != null) { datamodel.put("bicConsensusTree", TreeUtilities.toNewick(ModelTest.getConsensusBIC().getConsensus(), true, true, true)); datamodel.put("consensusType", ModelTest.getConsensusBIC().getConsensusType()); } datamodel.put("doDTAveragedPhylogeny", ModelTest.getConsensusDT() != null ? new Integer(1) : new Integer(0)); if (ModelTest.getConsensusDT() != null) { datamodel.put("dtConsensusTree", TreeUtilities.toNewick(ModelTest.getConsensusDT().getConsensus(), true, true, true)); datamodel.put("consensusType", ModelTest.getConsensusDT().getConsensusType()); } // Process the template using FreeMarker try { freemarkerDo(datamodel, "index.html", outputFile); } catch (Exception e) { System.out.println("There was a problem building the html log files: " + e.getLocalizedMessage()); } }
From source file:org.apache.hadoop.hive.ql.metadata.formatting.MetaDataFormatUtils.java
private static String formatDate(long timeInSeconds) { if (timeInSeconds != 0) { Date date = new Date(timeInSeconds * 1000); return date.toString(); }//from ww w . ja v a 2s . c o m return "UNKNOWN"; }
From source file:com.unicornlabs.kabouter.reporting.PowerReport.java
public static void GeneratePowerReport(Date startDate, Date endDate) { try {//w ww.java2 s . c om Historian theHistorian = (Historian) BusinessObjectManager.getBusinessObject(Historian.class.getName()); ArrayList<String> powerLogDeviceIds = theHistorian.getPowerLogDeviceIds(); Document document = new Document(PageSize.A4, 50, 50, 50, 50); File outputFile = new File("PowerReport.pdf"); outputFile.createNewFile(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outputFile)); document.open(); document.add(new Paragraph("Power Report for " + startDate.toString() + " to " + endDate.toString())); document.newPage(); DecimalFormat df = new DecimalFormat("#.###"); for (String deviceId : powerLogDeviceIds) { ArrayList<Powerlog> powerlogs = theHistorian.getPowerlogs(deviceId, startDate, endDate); double total = 0; double max = 0; Date maxTime = startDate; double average = 0; XYSeries series = new XYSeries(deviceId); XYDataset dataset = new XYSeriesCollection(series); for (Powerlog log : powerlogs) { total += log.getPower(); if (log.getPower() > max) { max = log.getPower(); maxTime = log.getId().getLogtime(); } series.add(log.getId().getLogtime().getTime(), log.getPower()); } average = total / powerlogs.size(); document.add(new Paragraph("\nDevice: " + deviceId)); document.add(new Paragraph("Average Power Usage: " + df.format(average))); document.add(new Paragraph("Maximum Power Usage: " + df.format(max) + " at " + maxTime.toString())); document.add(new Paragraph("Total Power Usage: " + df.format(total))); //Create a custom date axis to display dates on the X axis DateAxis dateAxis = new DateAxis("Date"); //Make the labels vertical dateAxis.setVerticalTickLabels(true); //Create the power axis NumberAxis powerAxis = new NumberAxis("Power"); //Set both axes to auto range for their values powerAxis.setAutoRange(true); dateAxis.setAutoRange(true); //Create the tooltip generator StandardXYToolTipGenerator ttg = new StandardXYToolTipGenerator("{0}: {2}", new SimpleDateFormat("yyyy/MM/dd HH:mm"), NumberFormat.getInstance()); //Set the renderer StandardXYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.LINES, ttg, null); //Create the plot XYPlot plot = new XYPlot(dataset, dateAxis, powerAxis, renderer); //Create the chart JFreeChart myChart = new JFreeChart(deviceId, JFreeChart.DEFAULT_TITLE_FONT, plot, true); PdfContentByte pcb = writer.getDirectContent(); PdfTemplate tp = pcb.createTemplate(480, 360); Graphics2D g2d = tp.createGraphics(480, 360, new DefaultFontMapper()); Rectangle2D r2d = new Rectangle2D.Double(0, 0, 480, 360); myChart.draw(g2d, r2d); g2d.dispose(); pcb.addTemplate(tp, 0, 0); document.newPage(); } document.close(); JOptionPane.showMessageDialog(null, "Report Generated."); Desktop.getDesktop().open(outputFile); } catch (FileNotFoundException fnfe) { JOptionPane.showMessageDialog(null, "Unable To Open File For Writing, Make Sure It Is Not Currently Open"); } catch (IOException ex) { Logger.getLogger(PowerReport.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(PowerReport.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:dk.netarkivet.common.webinterface.HTMLUtils.java
/** * Get an HTML representation of the date given. * * @param d A date/*from www. j a v a 2 s. co m*/ * @return A representation of the date that can be directly inserted into an HTML document, or the empty string if * d is null. * @deprecated Please use <fmt:date> from taglib instead. */ public static String makeDate(Date d) { if (d == null) { return ""; } else { return escapeHtmlValues(d.toString()); } }
From source file:org.grouplens.samantha.server.indexer.IndexerUtilities.java
/** * TODO: deal with timezone problem./* ww w .j a v a 2 s .c om*/ * @param timeStr yyyy-MM-dd HH:mm:SS or now/today - <n> <TIMEUNIT string value in Java> */ public static int parseTime(String timeStr) { try { Date date; if (timeStr.startsWith("now") || timeStr.startsWith("today")) { String[] fields = timeStr.split(" "); long mul = Long.parseLong(fields[2]); String unit = fields[3]; long current = new Date().getTime(); if (timeStr.startsWith("today")) { DateFormat format = new SimpleDateFormat("yyyy-MM-dd"); current = format.parse(format.format(new Date())).getTime(); } long minus = TimeUnit.valueOf(unit).toMillis(mul); date = new Date(current - minus); } else if (timeStr.split("-").length > 1) { DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:SS"); date = format.parse(timeStr); } else { return Integer.parseInt(timeStr); } Logger.info("{}", date.toString()); return (int) (date.getTime() / 1000); } catch (ParseException e) { throw new ConfigurationException(e); } }
From source file:org.mifos.framework.util.helpers.DateUtils.java
public static String getLocalDateString(DateTime date, Locale locale) throws InvalidDateException { // the following line is for 1.1 release and will be removed when date // is localized locale = internalLocale;//from w w w . j a va2 s .co m Calendar calendar = date.toCalendar(locale); java.sql.Date currentDate = new java.sql.Date(calendar.getTimeInMillis()); SimpleDateFormat format = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, locale); String userfmt = convertToCurrentDateFormat(format.toPattern()); return convertDbToUserFmt(currentDate.toString(), userfmt); }