I am trying to parse a date/time json from server side inside bind viewholder. The date string am trying to parse is this:
2018-06-25T08:06:52Z
The time set to the text view is the same as before parsing.
This is because you're not passing in a new SimpleDateFormat.
Try this:
final String serverDate = "2018-06-25T08:06:52Z"
final SimpleDateFormat serverDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
final SimpleDateFormat yourDateFormat = new SimpleDateFormat("yyyy-MM-dd"); // put whatever you want here!
try {
final Date date = serverDate.parse(serverDateFormat);
final String formattedDate = yourDateFormat.format(date);
} catch (ParseException e) {
System.out.println(e.toString());
}
This way you're interpreting the String with the server format into a pure Date object. You're then free to do what you wish with that object and turn it into whichever format you want (by providing your new format).
For more information on building your date format pattern, see this link.