curioustechizen / android-ago

An Android TextView that always displays an auto refreshing relative time span with respect to a reference time

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SetText with Date String ?

amaydiam opened this issue · comments

How setText if I have String Date like "2015-08-02 01:01:50" ?

@amaydiam Currently, the library expects the date in milliseconds since epoch format - for example, the format returned by System.currentTimeMillis(). If you receive the date in String format, you need to first convert it to a long. Something along the following lines should work (Note:- This code is not tested*

//Declare SDF as a static somewhere
static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

//Then, wherever you receive the String date, do this
long dateAsLong = DATE_FROMAT.parse(stringDate).getTime();
relativeTimeTextView.setReferenceTime(dateAsLong);