1

I have a date object from javascript that is converted into a string in the format like this

2014-05-22T15:27:49.125Z

Now in my java file, i am using Gson and create my builder like so

Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.sssZ").create();

To convert the date from the string value into a Date object, i am using this.

Date myDate = gson.fromJson(options.getString("dateAsString"), Date.class);

This seems to report this error?

05-22 16:29:19.484: W/System.err(24636): java.lang.IllegalArgumentException: Parse error: 2014-05-22T15:27:49.125Z

Any help appreciated

1 Answer 1

2

If the issue is with date format then try any one:

SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",Locale.US);

OR

SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.US);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.