0

I am trying to get the date format from a string which is saved in sharedpreferences.datetime parsing error

As you can see the wrong date in the picture.current date is 19/11/2015 but after parsing it is changed to "Mon Jul 11 ..."something.please find some help for me. Thank you.

2
  • come on man!how can you negative this question.if you think this is a silly question then answer back.(sorry guys this is not for all,this is just for the one who gave negative vote.) Commented Nov 19, 2015 at 9:12
  • Correct your format. m is used for Minute in hour whereas M is used as Month in year. Commented May 9, 2021 at 15:17

2 Answers 2

3

Your dateobg returning from web service is : 11-19-2015.

You try to get the date from this string, you should in this case use the correct SimpleDateFormat.

SimpleDateFormat format = new SimpleDateFormat("MM-dd-yyyy", Locale.getDefault());
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks buddy.Actually i din't observe the format that i am receiving.thanks again.
but still i din't solve the issue.it is now showing as Mon Jan 19 2015
Show the response of your web service again.
yeah it worked now for me after a little change in the code.Thanks man.
0

Use SimpleDateFormat for that

public String getDateTime(){    
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd 00:00:00", Locale.ENGLISH);
    Date date = new Date();
    return format.format(date)+"" ; 
}

1 Comment

The question is asking about converting string to date, isn't it?

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.