java - Remove the hour,minute and seconds from date gotten from server as JSON -
i getting json data server includes dates too. shows date 2017-07-20 00:00:00
want see date this:2017-07-20
, , checked previous questions issue of them based on date in android side. , problem date json , because of don't know how remove time it.
did try simple parse string this?
string date_string = "2017-07-20 00:00:00"; string[] parsed = date_string.split(" "); string your_wanted_string = parsed[0]; system.out.println(your_wanted_string);
edit
- you have convert string
date
here : https://stackoverflow.com/a/4216767/1979882 - convert date milliseconds. or use calendar class.
- calculate difference between values.
an example:
http://www.mkyong.com/java/how-do-get-time-in-milliseconds-in-java/
public class timemilisecond { public static void main(string[] argv) throws parseexception { simpledateformat sdf = new simpledateformat("dd-m-yyyy hh:mm:ss"); string dateinstring = "22-01-2015 10:20:56"; date date = sdf.parse(dateinstring); system.out.println(dateinstring); system.out.println("date - time in milliseconds : " + date.gettime()); calendar calendar = calendar.getinstance(); calendar.settime(date); system.out.println("calender - time in milliseconds : " + calendar.gettimeinmillis()); } }
Comments
Post a Comment