0

Dear Folks ,
I am having the problem in converting a string "2014-05-22T14:21:54.677" to a date object in android . I have used following approach

SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ");

dateFormater.parse("2014-05-22T14:21:54.677");

I am getting java.text.parseexception . Please help me out how can i convert it to a date object?

3 Answers 3

3

Try it:

String dateString = "22/05/2014 11:49:00 AM";
    SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss aa");
    Date convertedDate = new Date();
    try {
        convertedDate = dateFormat.parse(dateString);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    System.out.println(convertedDate);

Please try it and tell me

EDIT

and if you try put the same format?

//......

SimpleDateFormat  dateFormat = new SimpleDateFormat("MM/dd/yyyy'T'HH:mm:ss'Z'");
//.....
Sign up to request clarification or add additional context in comments.

2 Comments

Hi Aspicas, thanks for quick help. i get the date string from the web service which is in 2014-05-22T14:21:54.677 the 'T' in between causing me the problem while parsing!
The format yyyy-MM-dd'T'hh:mm:ss.sss worked for me ! Thanks for the help :)
0

Try this One. it was work for me.

SimpleDateFormat sdf = new SimpleDateFormat("dd-M-yyyy hh:mm:ss");
String dateInString = "31-08-1982 10:20:56";
Date date = sdf.parse(dateInString);
System.out.println(date); //Tue Aug 31 10:20:56 SGT 1982

2 Comments

Hi VP. i get the date string from the web service which is in 2014-05-22T14:21:54.677 the 'T' in between causing me the problem while parsing!
Hi nsm: you need this "T" for any condition, if no then please 1st delete this "T" from string and after set date parser if you need please give me details where you want.
0

I used this code and the answer i got is...

enter image description here

2 Comments

Hi Abhi. Thank for the quick help. But I am getting this string date value from a web service and i need to store it as date object . So I am stuck in this part . Please guide me further
try to get through the above method and check whether you are getting the same problem

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.