I am new to android studio and java development.
I would like to parse this date:
"2017-04-26T20:55:00.000Z"
, which I am getting from a hash map string.
I would like to display only the date on my view.
I am new to android studio and java development.
I would like to parse this date:
"2017-04-26T20:55:00.000Z"
, which I am getting from a hash map string.
I would like to display only the date on my view.
You can always use Java's DateFormat
API for achieving this. Here is the code snippet that will help you to achieve whatever task you are looking for.
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
Date date = dateFormat.parse("2017-04-26T20:55:00.000Z");//You will get date object relative to server/client timezone wherever it is parsed
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); //If you need time just put specific format for time like 'HH:mm:ss'
String dateStr = formatter.format(date);
You will get date object from which you can use it whichever way you would like to display using date formatter to format again.
In my opinion the cleanest way to do it :
You could use substring like so
String date = yourString.substring(0, 10);
This would pull all the characters from 0 to 10 in your String and save it as a new String.
In this case that would return "2017-04-26"