List of usage examples for org.apache.commons.lang.time DateFormatUtils ISO_DATETIME_FORMAT
FastDateFormat ISO_DATETIME_FORMAT
To view the source code for org.apache.commons.lang.time DateFormatUtils ISO_DATETIME_FORMAT.
Click Source Link
From source file:Main.java
public static void main(String[] args) { Date today = new Date(); String timestamp = DateFormatUtils.ISO_DATETIME_FORMAT.format(today); System.out.println("timestamp = " + timestamp); }
From source file:com.ikanow.infinit.e.harvest.utils.DateUtility.java
public synchronized static long parseDate(String sDate) { if (null == _allowedDatesArray_startsWithLetter) { _allowedDatesArray_startsWithLetter = new String[] { DateFormatUtils.SMTP_DATETIME_FORMAT.getPattern(), "MMM d, yyyy hh:mm a", "MMM d, yyyy HH:mm", "MMM d, yyyy hh:mm:ss a", "MMM d, yyyy HH:mm:ss", "MMM d, yyyy hh:mm:ss.SS a", "MMM d, yyyy HH:mm:ss.SS", "EEE MMM dd HH:mm:ss zzz yyyy", "EEE MMM dd yyyy HH:mm:ss zzz", "EEE MMM dd yyyy HH:mm:ss 'GMT'Z (zzz)", }; _allowedDatesArray_numeric_1 = new String[] { "yyyy-MM-dd'T'HH:mm:ss'Z'", DateFormatUtils.ISO_DATE_FORMAT.getPattern(), DateFormatUtils.ISO_DATE_TIME_ZONE_FORMAT.getPattern(), DateFormatUtils.ISO_DATETIME_FORMAT.getPattern(), DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern() }; _allowedDatesArray_numeric_2 = new String[] { "yyyyMMdd", "yyyyMMdd hh:mm a", "yyyyMMdd HH:mm", "yyyyMMdd hh:mm:ss a", "yyyyMMdd HH:mm:ss", "yyyyMMdd hh:mm:ss.SS a", "yyyyMMdd HH:mm:ss.SS", // Julian, these are unlikely "yyyyDDD", "yyyyDDD hh:mm a", "yyyyDDD HH:mm", "yyyyDDD hh:mm:ss a", "yyyyDDD HH:mm:ss", "yyyyDDD hh:mm:ss.SS a", "yyyyDDD HH:mm:ss.SS", }; _allowedDatesArray_stringMonth = new String[] { "dd MMM yy", "dd MMM yy hh:mm a", "dd MMM yy HH:mm", "dd MMM yy hh:mm:ss a", "dd MMM yy HH:mm:ss", "dd MMM yy hh:mm:ss.SS a", "dd MMM yy HH:mm:ss.SS", }; _allowedDatesArray_numericMonth = new String[] { "MM dd yy", "MM dd yy hh:mm a", "MM dd yy HH:mm", "MM dd yy hh:mm:ss a", "MM dd yy HH:mm:ss", "MM dd yy hh:mm:ss.SS a", "MM dd yy HH:mm:ss.SS", }; }// w ww . j av a 2 s .co m // Starts with day or month: String sDateTmp = sDate; if (Character.isLetter(sDate.charAt(0))) { try { Date date = DateUtils.parseDate(sDate, _allowedDatesArray_startsWithLetter); return date.getTime(); } catch (Exception e) { } // keep going } //TESTED else if (Character.isLetter(sDate.charAt(5))) { // month must be string, doesn't start with day though try { int index = sDate.indexOf(':'); if (index > 0) { sDate = new StringBuffer(sDate.substring(0, index).replaceAll("[./-]", " ")) .append(sDate.substring(index)).toString(); } else { sDate = sDate.replaceAll("[ ./-]", " "); } Date date = DateUtils.parseDate(sDate, _allowedDatesArray_stringMonth); return date.getTime(); } catch (Exception e) { } // keep going } //TESTED else { // Starts with a number most likely... int n = 0; for (; n < 4; ++n) { if (!Character.isDigit(sDate.charAt(n))) { break; } } if (4 == n) { // (Probably starts with a year) // One of the formal formats starting with a year try { Date date = DateUtils.parseDate(sDate, _allowedDatesArray_numeric_1); return date.getTime(); } catch (Exception e) { } // keep going // Something more ad hoc starting with a year try { int index = sDate.indexOf(':'); if (index > 0) { sDate = new StringBuffer(sDate.substring(0, index).replace("-", "")) .append(sDate.substring(index)).toString(); } else { sDate = sDate.replace("-", ""); } Date date = DateUtils.parseDate(sDate, _allowedDatesArray_numeric_2); return date.getTime(); } catch (Exception e) { } // keep going } //TESTED // Probably starts with a day try { int index = sDate.indexOf(':'); if (index > 0) { sDate = new StringBuffer(sDate.substring(0, index).replaceAll("[./-]", " ")) .append(sDate.substring(index)).toString(); } else { sDate = sDate.replaceAll("[./-]", " "); } Date date = DateUtils.parseDate(sDate, _allowedDatesArray_numericMonth); return date.getTime(); } //TESTED catch (Exception e) { } // keep going } sDate = sDateTmp; // If we're here, nothing's worked, try "natural language processing" try { return Chronic.parse(sDate).getBeginCalendar().getTime().getTime(); } //TESTED catch (Exception e2) { // Error all the way out throw new RuntimeException("Can't parse: " + sDate); } //TESTED }
From source file:eu.optimis.sm.gui.server.XmlUtil.java
public String getObjXml(String xml) { try {//from ww w .j ava 2s.c o m DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); Document doc = factory.newDocumentBuilder().parse(new InputSource(new StringReader(xml))); NodeList timestampList = doc.getElementsByTagName("metric_timestamp"); for (int i = 0; i < timestampList.getLength(); i++) { Element ts = (Element) timestampList.item(i); String tsLangType = ts.getTextContent(); try { long millis = 0; millis = Long.parseLong(tsLangType); Date udate = new Date(millis * 1000); String timestamp = DateFormatUtils.ISO_DATETIME_FORMAT.format(udate); ts.setTextContent(timestamp); } catch (NumberFormatException e) { } } String rs = xmlToString(doc); return rs; } catch (SAXException e) { return null; } catch (ParserConfigurationException e) { return null; } catch (IOException e) { return null; } }
From source file:eu.optimis.mi.gui.server.XmlUtil.java
public String getObjXml(String xml) { try {//from w w w. ja v a 2s. c o m // Create a builder factory DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); Document doc = factory.newDocumentBuilder().parse(new InputSource(new StringReader(xml))); NodeList timestampList = doc.getElementsByTagName("metric_timestamp"); for (int i = 0; i < timestampList.getLength(); i++) { Element ts = (Element) timestampList.item(i); String tsLangType = ts.getTextContent(); try { long millis = 0; millis = Long.parseLong(tsLangType); Date udate = new Date(millis * 1000); String timestamp = DateFormatUtils.ISO_DATETIME_FORMAT.format(udate); ts.setTextContent(timestamp); } catch (NumberFormatException e) { } } String rs = xmlToString(doc); return rs; } catch (SAXException e) { return null; } catch (ParserConfigurationException e) { return null; } catch (IOException e) { return null; } }
From source file:eu.optimis.mi.aggregator.util.XmlUtil.java
public String getObjXml(String xml) { try {/* w ww . j a v a2 s . c o m*/ // Create a builder factory DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); Document doc = factory.newDocumentBuilder().parse(new InputSource(new StringReader(xml))); NodeList timestampList = doc.getElementsByTagName("metric_timestamp"); for (int i = 0; i < timestampList.getLength(); i++) { Element ts = (Element) timestampList.item(i); String tsLangType = ts.getTextContent(); try { long millis = 0; millis = Long.parseLong(tsLangType); Date udate = new Date(millis * 1000); String timestamp = DateFormatUtils.ISO_DATETIME_FORMAT.format(udate); ts.setTextContent(timestamp); } catch (NumberFormatException e) { } } String rs = xmlToString(doc); return rs; } catch (SAXException e) { return null; } catch (ParserConfigurationException e) { return null; } catch (IOException e) { return null; } }
From source file:com.jaspersoft.studio.compatibility.JRXmlWriterHelper.java
public static String writeReport(JasperReportsContext jrContext, JRReport report, String encoding, String version) throws Exception { if (report == null) return null; encoding = fixencoding(encoding);/*ww w .j a va 2 s . c o m*/ if (!writers.contains(version)) version = LAST_VERSION; boolean disposeContext = false; if (jrContext == null) { jrContext = JasperReportsConfiguration.getDefaultJRConfig(); disposeContext = true; } jrContext.removeProperty(JRXmlBaseWriter.PROPERTY_REPORT_VERSION); if (writers.contains(version)) jrContext.setProperty(JRXmlBaseWriter.PROPERTY_REPORT_VERSION, version); String xml = null; try { // jrContext.setProperty("net.sf.jasperreports.components.table.version", version); xml = new JRXmlWriter(jrContext).write(report, encoding); // request Bug 37455 - [Case #48613] Simple jrxml timestamp on Save or Save As // + community bug #3936 over-aggressive time stamp String timestamp = ""; //$NON-NLS-1$ if (jrContext instanceof JasperReportsConfiguration) { if (((JasperReportsConfiguration) jrContext) .getPropertyBoolean(StudioPreferencePage.JSS_TIMESTAMP_ONSAVE, true)) { timestamp = "<!-- " + DateFormatUtils.ISO_DATETIME_FORMAT.format(new Date()) + " -->\n"; //$NON-NLS-1$ //$NON-NLS-2$ } } // Replace with a more meaningful JR version if (version.equals(LAST_VERSION)) { version = getInstalledJasperReportsVersion(); } // Get JSS bundle version String jssPluginVersion = JaspersoftStudioPlugin.getInstance().getBundle().getVersion().toString(); String jrVersionTxt = Messages.JRXmlWriterHelper_9 + version + " "; //$NON-NLS-2$ xml = xml.replaceFirst("<jasperReport ", "<!-- Created with Jaspersoft Studio version " //$NON-NLS-1$//$NON-NLS-2$ + jssPluginVersion + jrVersionTxt + " -->\n" + timestamp + "<jasperReport "); //$NON-NLS-1$ //$NON-NLS-2$ } finally { if (disposeContext) ((JasperReportsConfiguration) jrContext).dispose(); } return xml; }
From source file:com.squid.kraken.v4.caching.redis.queryworkerserver.QueryWorkerJobStatus.java
public String getStartTime() { return DateFormatUtils.ISO_DATETIME_FORMAT.format(start); }
From source file:eu.optimis.mi.aggregator.util.XmlUtil.java
public MonitoringResourceDatasets getMRDObj(String xml) { try {//from w w w .jav a 2 s.c o m // Create a builder factory DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); Document doc = factory.newDocumentBuilder().parse(new InputSource(new StringReader(xml))); NodeList msList = doc.getElementsByTagName("monitoring_resource"); ArrayList<MonitoringResourceDataset> rsList = new ArrayList<MonitoringResourceDataset>(); for (int i = 0; i < msList.getLength(); i++) { MonitoringResourceDataset mdata = new MonitoringResourceDataset(); Element ts = (Element) msList.item(i); Element eMetricname = (Element) ts.getElementsByTagName("metric_name").item(0); String sMetricname = eMetricname.getTextContent(); mdata.setMetric_name(sMetricname); Element eMetricvalue = (Element) ts.getElementsByTagName("metric_value").item(0); String sMetricvalue = eMetricvalue.getTextContent(); mdata.setMetric_value(sMetricvalue); Element eMetricunit = (Element) ts.getElementsByTagName("metric_unit").item(0); String sMetricunit = eMetricunit.getTextContent(); mdata.setMetric_unit(sMetricunit); Element eMetrictp = (Element) ts.getElementsByTagName("metric_timestamp").item(0); String tsLangType = eMetrictp.getTextContent(); Date date = null; try { long millis = Long.valueOf(tsLangType); date = new Date(millis * 1000); @SuppressWarnings("unused") String tp = DateFormatUtils.ISO_DATETIME_FORMAT.format(date); } catch (NumberFormatException e) { } mdata.setMetric_timestamp(date); Element eMinfoColType = (Element) ts.getElementsByTagName("monitoring_information_collector_id") .item(0); if (eMinfoColType != null) { String sMinfoColType = eMinfoColType.getTextContent(); mdata.setMonitoring_information_collector_id(sMinfoColType); } Element eResType = (Element) ts.getElementsByTagName("resource_type").item(0); if (eResType != null) { String sResType = eResType.getTextContent(); mdata.setResource_type(sResType); } Element ePResId = (Element) ts.getElementsByTagName("physical_resource_id").item(0); if (ePResId != null) { String sPResId = ePResId.getTextContent(); mdata.setPhysical_resource_id(sPResId); } Element eSResId = (Element) ts.getElementsByTagName("service_resource_id").item(0); if (eSResId != null) { String sSResId = eSResId.getTextContent(); mdata.setService_resource_id(sSResId); } Element eVResId = (Element) ts.getElementsByTagName("virtual_resource_id").item(0); if (eVResId != null) { String sVResId = eVResId.getTextContent(); mdata.setVirtual_resource_id(sVResId); } rsList.add(mdata); mdata = null; } MonitoringResourceDatasets mdatasets = new MonitoringResourceDatasets(); mdatasets.setMonitoring_resource(rsList); return mdatasets; } catch (SAXException e) { return null; } catch (ParserConfigurationException e) { return null; } catch (IOException e) { return null; } }
From source file:net.firejack.platform.web.statistics.manager.BaseStatisticsManager.java
@Override public void saveStatisticsBunch(List<LogEntry> partLogEntryList) { ServiceRequest<LogEntry> request = new ServiceRequest<LogEntry>(); request.setDataList(partLogEntryList); ServiceResponse serviceResponse = OPFEngine.StatisticsService.saveStatisticsBunch(request); String time = DateFormatUtils.ISO_DATETIME_FORMAT.format(new Date()); if (serviceResponse.isSuccess()) { logger.info("Statistics bunch was committed successfully at " + time); } else {/*from www. j av a 2 s . co m*/ logger.error("Statistics API Service response has failure status at " + time + ". Reason: " + serviceResponse.getMessage()); } }
From source file:de.smartics.maven.plugin.buildmetadata.io.SdocBuilder.java
private String formatDate(final String datePropertyKey) { final String originalDateString = buildMetaDataProperties.getProperty(datePropertyKey); if (StringUtils.isNotBlank(originalDateString)) { try {//from w ww.ja v a2 s. c o m final String originalPattern = buildMetaDataProperties .getProperty(Constant.PROP_NAME_BUILD_DATE_PATTERN); final DateFormat format = new SimpleDateFormat(originalPattern, Locale.ENGLISH); final Date date = format.parse(originalDateString); final String dateString = DateFormatUtils.ISO_DATETIME_FORMAT.format(date); return dateString; } catch (final ParseException e) { if (LOG.isDebugEnabled()) { LOG.debug("Cannot parse date of property '" + datePropertyKey + "': " + originalDateString + ". Skipping..."); } return null; } } return null; }