Question

I'm parsing a backoffice date (C#) \\/Date\\((\\d+)([-+]\\d+)?\\)\\/ with org.joda.time.DateTime

Example:
1 - BO date = /Date(1380891215020+0100)/
2 - DateTime BO date parsed = 2013-10-04T12:53:35.020+01:00
3 - Calendar.setTime(DateTime BO date parsed) = Fri Oct 04 12:53:35 GMT+01:00 2013
4 - String finalDate = Calendar.getTime().toString(); = Fri Oct 04 12:53:35 GMT+01:00 2013

At this point everything went ok. Now I want to make a date comparison so:

Date dateA = mySimpleDateFormat.parse(finalDate);
Calendar cal = Calendar.getInstance();
cal.setTime(dateA);
...

When I use mySimpeDateFormat to parse finalDate in some devices a

java.text.ParseException: Unparseable date: "Fri Oct 04 12:53:35 WEST 2013" (at offset 20)"

is thrown. HTC One S is one of that devices.

Phone Date & Time settings:
- Automatic date & time: true
- Automatic time zone: false


Any idea why is there WEST instead of GMT+01:00?
Thanks for your time.

Was it helpful?

Solution 3

Found the solution!
First of all thank you for your answers.

I forgot to say that my Locale was Locale.ENGLISH but the problem wasn't there, it was on step 4:

String finalDate  = mySimpleDateFormat.format(Calendar.getTime());

instead of

String finalDate = Calendar.getTime().toString(); 

Now I always have a date format like Fri Oct 04 12:53:35 GMT+01:00 2013 and everything works just fine ;)
Thanks!

OTHER TIPS

Device locale (deals with language and time) could be the problem. the finalDate string obviously is a timestamp in English, you device might not be.

I have been through similar problem. Use Calendar cal = Calendar.getInstance(Locale.US); instead. On some devices locale is not US and Calendar.getInstance() return Calendar in some other locale. Same goes for SimpleDateFormat, try using mySimpleDateFormat = new SimpleDateFormat(format, Locale.US);.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top