List of usage examples for org.joda.time.format DateTimeFormatter getPrinter
public DateTimePrinter getPrinter()
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 www . j av a 2 s. 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; }