Question

I'm trying to parse string representation of date. It looks like 20120306 14:21:35 MSK +0400. I'm using a SimpleDateFormat to parse it into a Date and a pattern string according to http://developer.android.com/reference/java/text/SimpleDateFormat.html

DATE_PATTERN = "yyyyMMdd kk:mm:ss z Z";
SimpleDateFormat dateFormat=new SimpleDateFormat(DATE_PATTERN);
Date date=dateFormat.parse(dateString);

I've try different z/Z combinations but have no result, except ParseException of course :)

Probably i'm doing something wrong, but what?

I'll be very glad for any help! Thanks in advance!

Was it helpful?

Solution

It doesn't recognise "MSK" as a valid time zone so try this instead:

String DATE_PATTERN = "yyyyMMdd kk:mm:ss z Z";
SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_PATTERN);
Date date = dateFormat.parse(dateString.replaceAll("MSK", "GMT"));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top