java - How to format date from json and set it into TextView -
i getting json response "publishedat": "2017-09-12t01:03:08z"
, want format response in simple date likeaug 12-09-2017 3:08
and set textview
using
date dateobj = new date(currentnews.gettimeinstring()); textview dateandtimeview = (textview) listitemview.findviewbyid(r.id.date_and_time); string formatteddateandtime = formatdateandtime(dateobj); dateview.settext(formatteddate); private string formatdateandtime(date dateobj){ simpledateformat dateformat = new simpledateformat("dd mmm, yyyy"); return dateformat.format(dateobj); }
did tried simpledateformat
? https://docs.oracle.com/javase/7/docs/api/java/text/simpledateformat.html
something (pseudocode, can`t test here)
string givendate = "2017-09-12t01:03:08z"; simpledateformat sdf= new simpledateformat("mm-dd-yyyy hh:mm:ss"); try { date date = sdf.parse(givendate ); system.out.println(date); } catch (parseexception e) { e.printstacktrace(); }
Comments
Post a Comment