implementing pretty time to format Date time in android -
i implementing pretty time library site http://www.ocpsoft.org/prettytime/ formatted date string text in android application.
i feeding date string local sqlite database,
string datestring="2015-09-25 15:00:47"; simpledateformat dateformat = new simpledateformat("mm/dd/yyyy hh:mm:ss aa"); date converteddate = new date(); try { converteddate = dateformat.parse(datestring); } catch (parseexception e) { // todo auto-generated catch block e.printstacktrace(); } prettytime p = new prettytime(); string datetime= p.format(converteddate); textview.settext(datetime);
i want able date formatted parsetext
2 minutes ago 1 day ago ...
however snippet codes above gives me text , avoids time. gives
minutes ago ...
please there need do, grateful if help. thanks
you're not passing date prettytime
object, because date-conversion fails. confirm in logcat.
the problem you're passing different date format , 24h time date format:
simpledateformat dateformat = new simpledateformat("mm/dd/yyyy hh:mm:ss aa");
you can either change date format string use 24h time , match date format, so:
string datestring="2015-09-25 15:00:47"; simpledateformat dateformat = new simpledateformat("yyyy-mm-dd kk:mm:ss");
or change time pass in be:
string datestring="09/25/2015-09-25 3:00:47 pm"; simpledateformat dateformat = new simpledateformat("mm/dd/yyyy hh:mm:ss aa");
Comments
Post a Comment