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.
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.
Let's see here - "now", "yesterday", "today", "tomorrow". Is that about it? :-)
JodaTime won't parse them for you but it should be trivial enough to write your own function (or enum) to do so; you can even throw in stuff like "day after tomorrow" if you feel like it.
"Now" seems to be the only value for which DateTime
would be appropriate, though - all others look more like LocalDate
(or, possibly, DateMidnight
) to me.
精彩评论