0

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.

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
GuilhE
  • 11,591
  • 16
  • 75
  • 116

3 Answers3

1

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.

Ivo
  • 18,659
  • 2
  • 23
  • 35
1

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);.

M-Wajeeh
  • 17,204
  • 10
  • 66
  • 103
0

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!

GuilhE
  • 11,591
  • 16
  • 75
  • 116