Date time parsing error from string format

▼魔方 西西 提交于 2019-12-13 04:49:04

问题


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

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.


回答1:


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



回答2:


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


来源:https://stackoverflow.com/questions/33799418/date-time-parsing-error-from-string-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!