Hi Bart, Thanks for the reply. I figured it out late yesterday. Maybe this will help in the future.
One of the append() overloads of DateTimeFormatterBuilder takes an array of DateTimeParsers and returns a DateTimeFormatter. The formatter runs all of the parsers and selects the "best" (whatever that means) of the parse results that do not fail. Here is a snip of the code I wrote yesterday. DateTimeFormatter fmt1 = DateTimeFormat.forPattern(dformat1); //Lazard date time //second format string is optional. If present we account for it in the size of the DateTimeParser array passed to the //DateTimeFormatterBuilder construtor below DateTimeFormatter fmt2 = null; DateTimeParser[] dtpa; if(dformat2 == null || dformat2.length()==0) { dtpa = new DateTimeParser[1]; //need only 1 slot in the parser array } else //the second format string exists { fmt2 = DateTimeFormat.forPattern(dformat2); //Lazard date time dtpa = new DateTimeParser[2]; //need a parser array big enough for the second format dtpa[1] = fmt2.getParser(); } dtpa[0] = fmt1.getParser(); //Try and parse using all parsers DateTimeFormatter fmt = new DateTimeFormatterBuilder().append(null, dtpa).toFormatter(); DateTime dt = fmt.parseDateTime(toBeFormatted); Still pretty clunky and more lines than doing a catch on Illegal Arg Exception but I'm willing to compromise for now. Sure beats writing a custom parser line by line. Also it may be worth going to a SimpleDateFormat object now that I know that will handle this situation Thanks again for your reply. Lenny Wintfeld bart zagers wrote: > Hi, > > I once asked the same question. It was a problem that showed when > switching from the standard Date/Calendar to Joda. The standard > SimpleDateFormat can handle it, but the DateTimeFormatter can't. > At that time there was no plan to change this behaviour. I solved it > by creating two formatters and choose the correct one based on a check > for a space at the specific index of the string. > > Bart > > On 5/1/08, Lenny Wintfeld <[EMAIL PROTECTED]> wrote: > >> Hi >> >> I've got a date string to be input to Joda. The string has the >> day-of-month left padded with a space for day-of -month smaller than >> 10. I'd like to create a DateTimeFormatter capable of dealing with this >> string. >> >> For instance January 10 2008 has a date string of "Jan 10 2008" (one >> space between the month name and day-of-month) >> but January 1 2008 has a date string of "Jan 1 2008" (two spaces >> between month name and day-of- month. >> >> I've experimented with various DateTimeFormat format strings with >> DateTimeFormatter dtf = DateTimeFormat.forPattern(<pattern goes here>) >> but without success. >> >> I thought of creating 2 formatters, one for single digit months and one >> for double digit months and running one of the formatter's >> parseDateTime() methods inside the catch block of the illegal argument >> exception generated by the other parser. But even if that works it seems >> like a pretty clunky wat to do it. >> >> Is there a clean reliable way to solve this problem (hopefully with a >> single DateTimeFormatter object?? >> >> Thanks in advance for your help. >> >> >> Lenny Wintfeld >> >> ------------------------------------------------------------------------- >> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference >> Don't miss this year's exciting event. There's still time to save $100. >> Use priority code J8TL2D2. >> >> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone >> _______________________________________________ >> Joda-interest mailing list >> Joda-interest@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/joda-interest >> >> > > ------------------------------------------------------------------------- > This SF.net email is sponsored by the 2008 JavaOne(SM) Conference > Don't miss this year's exciting event. There's still time to save $100. > Use priority code J8TL2D2. > http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone > _______________________________________________ > Joda-interest mailing list > Joda-interest@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/joda-interest > > > ------------------------------------------------------------------------- This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone _______________________________________________ Joda-interest mailing list Joda-interest@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/joda-interest