M
M
MonsterAndrew2017-10-07 21:08:35
Java
MonsterAndrew, 2017-10-07 21:08:35

How to properly format date "Oct 06" in Java JodaTime?

There is a date "Oct 06", I tried to format it like this:

DateTime to_date = DateTimeFormat.forPattern("M d").parseDateTime(massive.get(i).date);

But it doesn't work, it pops up:
Exception in thread "main" java.lang.IllegalArgumentException: Invalid format: "Oct 06"

Everything seems to be according to the documentation, "M" => month, "d" => day of the month, but it doesn't work(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2017-10-07
@MonsterAndrew

The current locale is probably Russian, so "Oct" is expected instead of " M ", not "Oct". But you can also explicitly specify the locale:

DateTimeFormat
  .forPattern("M d")
  .withLocale(Locale.US)
  .parseDateTime(massive.get(i).date);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question