Saturday, 10 December 2016

date - Java SimpleDateFormat not working

I am displaying the date and time in Android with this format:
2015-11-25 23:25:00




How can I change it to the following format?
2015-11-25



I wrote some code ,but not working correctly.



    public static Date toDate(boolean isCurrentDate, String dateString) {
Date date=null;
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
try {
if (isCurrentDate)

date = new Date();
else
date = formatter.parse(dateString);
System.err.println("Printresult" + formatter.parse(formatter.format(date)));

} catch (ParseException e1) {
e1.printStackTrace();
}

System.err.println("Printresult2" + date.toString());

return date;
}


I log and result is like this



Wed Nov 25 00:00:00 GMT+00:00 2015


How i can change date format like this : ? (2015-11-25)

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...