Rushi Ayyappa
Rushi Ayyappa

Reputation: 2848

Date time parsing error from string format

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.

Upvotes: 0

Views: 950

Answers (2)

Iamat8
Iamat8

Reputation: 3906

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)+"" ; 
}

Upvotes: 0

Farouk Touzi
Farouk Touzi

Reputation: 3456

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

Upvotes: 3

Related Questions