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

Time ago calculation

thamer898 opened this issue · comments

Hello

why every time the calculations display "in 23 hours " what is the problem ?

Regards

@thamer898 could you provide some sample code?

Hello

please see this code

//created at a value from server as an example it's value "2016-04-22T20:21:43.405Z"

RelativeTimeTextView v = (RelativeTimeTextView) convertView.findViewById(R.id.timestamp); //Or just use Butterknife!
v.setReferenceTime(createdAt.getTime());

Regards

Hello

@curioustechizen any updates ?

Regards

You'll have to provide a little more information I'm afraid. What did you expect the output to be? What was the actual time on the phone when you set the server time?

Hello

this is the message delivery time from server : Sun Apr 24 23:01:18 EEST 2016
so i get the time by this variable long now = new Date().getTime();

after that this is the calculation method
String Date = DateUtils.getRelativeTimeSpanString(
createdAt.getTime(),
now,
DateUtils.SECOND_IN_MILLIS).toString();

Regards

Hello

i want to display a message time like "just now" , 1 minute ago and so on .

Regards

If you see "in 23 hours" then probably the time you get from server is in the future. I can't think of any other explanation.

great what is the best time zone for my server that i should consider it ? kindly advice

@curioustechizen thank you very much this is a problem from my server i change the time zone to be +3 and i solved the problem but how it will be for the countries for multiple time zones ?

@thamer898 You are responsible for ensuring that the value you pass to setReferenceTime() is in the appropriate time zone. This library uses System.currentTimeMillis() method to get the current time on the Android device and compare it against the reference time you passed it. Since System.currentTimeMillis() is always in UTC time zone, you could try converting the time you get from your server into UTC (i.e., time since epoch) format and then passing it to setReferenceTime()

@curioustechizen right now am using a windows server 2012 r2 but right now am confused about the best time zone for different regions around the world do you have and advice about suitable time zone for that ?

@thamer898 You have 2 options:

  1. Your server always returns the time in UTC
  2. Your server returns time in whatever time zone it is in and in your app you convert it to UTC before setting it using setReferenceTime

Hello @curioustechizen

Yes i saved a value as UTC in my server so is it fit all time zones ?

Regards