3

I'm trying to get Date from String,

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
Date date = simpleDateFormat.parse(dateString);

My date string is:

Wed, 02 September 2015 08:27:00 MSK

I'm getting this error:

java.text.ParseException: Unparseable date: "Wed, 02 September 2015 08:27:00 MSK" (at offset 32)

What's wrong? Thx for help.

llaerto
  • 251
  • 1
  • 2
  • 11

2 Answers2

5

I see that you have MSK time. Is your locale English or Russian ? Because if your locale is Russian, September is not a valid month. So, you have 2 options :

  1. Change your locale to English.
  2. Let your locale in Russian, but write the month in Russian.

Fix for changing the locale to English :

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.ENGLISH);
Cosmin
  • 1,482
  • 12
  • 26
1

Make sure you're using the correct locale. Here you have Wed, 02 September 2015 08:27:00 MSK as Date String which include MSK which is TimeZone of Russia, Moscow. so you need to set TimeZone for it

Try this:

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("MCK"));
Date date = simpleDateFormat.parse(dateString);
Rajesh Jadav
  • 12,801
  • 5
  • 53
  • 78