List of usage examples for org.apache.commons.lang.time DateFormatUtils ISO_DATETIME_TIME_ZONE_FORMAT
FastDateFormat ISO_DATETIME_TIME_ZONE_FORMAT
To view the source code for org.apache.commons.lang.time DateFormatUtils ISO_DATETIME_TIME_ZONE_FORMAT.
Click Source Link
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", }; }//from www. j a v a2 s . c o 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:com.discursive.jccook.lang.DateFormatExample.java
public void testSimpleFormat() throws Exception { Date now = new Date(); logger.debug(DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(now)); }
From source file:com.smartitengineering.cms.api.impl.content.DateTimeFieldValueImpl.java
@Override protected String getValueAsString() { Date date = getValue();//w w w . j a v a2 s . co m if (date != null) { return DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(date); } return super.getValueAsString(); }
From source file:com.discursive.jccook.lang.DateFormatExample.java
public void testRoundedDates() throws Exception { FastDateFormat sdf = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT; Date now = new Date(); Date nearestHour = DateUtils.round(now, Calendar.HOUR); Date nearestMonth = DateUtils.round(now, Calendar.MONTH); Date nearestYear = DateUtils.round(now, Calendar.YEAR); logger.debug("now: " + sdf.format(now)); logger.debug("round hour: " + sdf.format(nearestHour)); logger.debug("round month: " + sdf.format(nearestMonth)); logger.debug("round year: " + sdf.format(nearestYear)); }
From source file:com.ecyrd.jspwiki.dav.items.DirectoryItem.java
public Collection getPropertySet() { ArrayList<Element> ts = new ArrayList<Element>(); Namespace davns = Namespace.getNamespace("DAV:"); ts.add(new Element("resourcetype", davns).addContent(new Element("collection", davns))); Element txt = new Element("displayname", davns); txt.setText(m_path.getName());/*from w w w . ja va2 s . c o m*/ ts.add(txt); ts.add(new Element("getcontentlength", davns).setText("0")); ts.add(new Element("getlastmodified", davns) .setText(DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(new Date()))); return ts; }
From source file:com.ecyrd.jspwiki.dav.items.PageDavItem.java
protected Collection<Element> getCommonProperties() { ArrayList<Element> set = new ArrayList<Element>(); set.add(new Element("resourcetype", m_davns)); set.add(new Element("creator", m_dcns).setText(m_page.getAuthor())); set.add(new Element("getlastmodified", m_davns) .setText(DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(m_page.getLastModified()))); set.add(new Element("displayname", m_davns).setText(m_page.getName())); return set;//from w w w .ja v a 2 s.c o m }
From source file:com.smartitengineering.exim.impl.xml.GenericDataTypeExporter.java
public void exportElement(AssociationType type, Object object, TransformerHandler handler) throws IOException { if (type == null || object == null || handler == null) { throw new IOException("All parameters are required!"); }/*from ww w . j a v a 2 s . co m*/ final String elementName = type.getSimpleName(); final String value; switch (type) { case TYPE_DATE: value = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format((Date) object); break; case TYPE_STRING: case TYPE_INTEGER: case TYPE_LONG: case TYPE_FLOAT: case TYPE_DOUBLE: case TYPE_BOOLEAN: default: value = object == null ? null : object.toString(); break; } try { AttributesImpl atts = new AttributesImpl(); handler.startElement(EXIM_COLLECN_URI, EXIM_COLLECTION_NS, elementName, atts); if (AssociationType.TYPE_STRING.equals(type)) { handler.startCDATA(); } final char[] chars; if (StringUtils.isBlank(value)) { chars = "".toCharArray(); } else { chars = value.toCharArray(); } handler.characters(chars, 0, chars.length); if (AssociationType.TYPE_STRING.equals(type)) { handler.endCDATA(); } handler.endElement(EXIM_COLLECN_URI, EXIM_COLLECTION_NS, elementName); } catch (Exception exception) { throw new IOException(exception); } }
From source file:com.discursive.jccook.lang.DateFormatExample.java
public void testTruncate() throws Exception { Date now = new Date(); Date truncYear = DateUtils.truncate(now, Calendar.YEAR); Date truncMonth = DateUtils.truncate(now, Calendar.MONTH); logger.debug("now: " + DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(now)); logger.debug("truncYear: " + DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(truncYear)); logger.debug("truncMonth: " + DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(truncMonth)); }
From source file:com.discursive.jccook.lang.DateFormatExample.java
public void testIterator() throws Exception { Date now = new Date(); logger.debug("now: " + DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(now)); Iterator iter = DateUtils.iterator(now, DateUtils.RANGE_WEEK_SUNDAY); while (iter.hasNext()) { Calendar cal = (Calendar) iter.next(); Date cur = cal.getTime(); logger.debug("iterate: " + DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(cur)); }/*from ww w . ja v a2 s . co m*/ }
From source file:com.discursive.jccook.lang.DateFormatExample.java
public void testFormatUTC() throws Exception { Date now = new Date(); logger.debug("now: " + DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(now)); logger.debug("UTC Time: " + DateFormatUtils.formatUTC(now, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern())); }