Is it possible to create a single DateTimeParser which would parse:
- dates with time given
- dates without time (assuming time to be start of day)
- times without dates (assuming date to be today)
or do I need to have three separate parsers, and try parsing strings with each one?
In other words, is it possible to define optional fields in a parser?
org.joda.time.format.ISODateTimeFormathas a static methoddateOptionalTimeParser()that uses the code below, based on theDateTimeFomatterBuilderclass, which has anappendOptionalmethod – you would probably be able to adapt the method to your requirement… Link: http://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormatterBuilder.html