Akram
Akram

Reputation: 493

SimpleDateFormat Error in android

I'm using toLocaleString() method to get this output "16 déc. 2012 23:00:28" and then when I want to get the date back, I get Unparseable date error.

String s = "16 déc. 2012 23:00:28";
SimpleDateFormat  format = new SimpleDateFormat("dd MMM. yyyy HH:mm:ss");
Date d = format.parse(s);

Upvotes: 2

Views: 620

Answers (2)

Evgeniy Dorofeev
Evgeniy Dorofeev

Reputation: 136112

This should work in your case

new SimpleDateFormat("dd MMM yyyy HH:mm:ss").parse(s);

your default locale is French, just remove '.'

Upvotes: 1

Francisco Paulo
Francisco Paulo

Reputation: 6322

Two things at play here:

  • You should supply the locale (I believe French in your case?)
  • The dot is part of the month short representation, so you are missing an 'M'

Try this:

SimpleDateFormat  format = new SimpleDateFormat("dd MMMM yyyy HH:mm:ss", Locale.FRENCH);

Upvotes: 5

Related Questions