Search code examples
javaparsingjodatimerelative-date

Can I parse relative times with JodaTime?


I'd love to be able to parse relative strings like now and yesterday and get JodaTime DateTimes. Is it possible? DateTimeFormat.forPattern and doesn't seem to support English relative times and I don't know of any other parsing options in JodaTime.

I should add that I'm using scala-time but can easily drop down to the actual JodaTime classes.


Solution

  • You would need to write either a separate library, or a DateTimeParser. DateTimeParser is the interface used internally by Joda-Time to parse text. Anyone can implement it and plug it directly into the Joda-Time parsing system using DateTimeFormatterBuilder.