List of usage examples for org.joda.time.format DateTimeFormatterBuilder append
public DateTimeFormatterBuilder append(DateTimePrinter printer, DateTimeParser[] parsers)
From source file:com.quinsoft.zeidon.utils.JoeUtils.java
License:Open Source License
/** * Returns a DateTimeFormatter that can parse and print dates in the format of * editString. There can be multiple edit strings which are separated by a "|" * character. If there are more than one then the first one is considered to * be the "print" format./*from ww w.ja v a 2s . c o m*/ * * NOTE: Automatically adds ISO 8601 parser: 2016-11-29T05:41:02+00:00 * * @param editString * @return */ public static DateTimeFormatter createDateFormatterFromEditString(String editString) { String[] strings = editString.split("\\|"); DateTimeParser list[] = new DateTimeParser[strings.length + 1]; DateTimePrinter printer = null; for (int i = 0; i < strings.length; i++) { try { DateTimeFormatter f = DateTimeFormat.forPattern(strings[i]); if (printer == null) printer = f.getPrinter(); list[i] = f.getParser(); } catch (Exception e) { throw ZeidonException.wrapException(e).appendMessage("Format string = %s", strings[i]); } } list[strings.length] = ISODateTimeFormat.dateTimeParser().getParser(); DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder(); builder.append(printer, list); DateTimeFormatter formatter = builder.toFormatter(); return formatter; }
From source file:org.mule.modules.quickbooks.utils.QBDateAdapter.java
License:Open Source License
public QBDateAdapter() { DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder(); DateTimeParser[] parsers = { ISODateTimeFormat.dateTimeNoMillis().getParser(), ISODateTimeFormat.dateTime().getParser(), DateTimeFormat.forPattern("yyyy-MM-ddZ").withZone(DateTimeZone.getDefault()).getParser() }; builder.append(ISODateTimeFormat.dateTimeNoMillis().getPrinter(), parsers); dateTimeFormatter = builder.toFormatter(); }
From source file:org.ojbc.util.xml.XmlUtils.java
License:RPL License
public static final DateTime parseXmlDateTime(String dateTime) { if (dateTime == null || dateTime.trim().equals("")) { return null; }// ww w . j a v a 2 s. co m DateTimeParser[] parsers = new DateTimeParser[] { DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss").getParser(), ISODateTimeFormat.dateTimeNoMillis().withOffsetParsed().getParser(), DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSS").getParser(), ISODateTimeFormat.dateTime().withOffsetParsed().getParser(), }; DateTimeFormatterBuilder dateTimeFormatterBuilder = new DateTimeFormatterBuilder(); dateTimeFormatterBuilder.append(null, parsers); return dateTimeFormatterBuilder.toFormatter().parseDateTime(dateTime); }
From source file:org.ojbc.util.xml.XmlUtils.java
License:RPL License
/** * This method accepts an XML date string and will return a JodaTime object. * It will need to be updated to support timezones. * /*w w w.j ava2 s .c o m*/ * @param date * @return */ public static final DateTime parseXmlDate(String date) { if (date == null || date.trim().equals("")) { return null; } DateTimeParser[] parsers = new DateTimeParser[] { DateTimeFormat.forPattern("yyyy-MM-dd").getParser(), ISODateTimeFormat.dateTimeNoMillis().withOffsetParsed().getParser(), }; DateTimeFormatterBuilder dateTimeFormatterBuilder = new DateTimeFormatterBuilder(); dateTimeFormatterBuilder.append(null, parsers); return dateTimeFormatterBuilder.toFormatter().parseDateTime(date); }