1

I'm trying to convert a date to relative date.

For example

12-03-2017 --> 2 years ago.

I'm using an android class which is "DateUtils.getRelativeTimeSpanString"

This class works just fine. But I have a little problem.

My app will serve in Turkish language. But method returns some very old sentence.

When relative time is equal to "2 days ago" class must return "2 gün önce" which is literal translation of "2 days ago". But instead it returns "Evvelsi gün" Which has same meaning but old sentence and I don't want to use that

How to change this string for Turkish language.

I did this:

if(DateUtils.getRelativeTimeSpanString(list.get(position).getCreatedAt().getTime(), System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS).toString().toLowerCase().equals("evvelsi gün")){
    //if class retuned unwanted word then dont use it but use preferred word.
    holder.postdate.setText("2 gün önce"); 
}
else{
    //if class returned preferred word use it
    holder.postdate.setText(DateUtils.getRelativeTimeSpanString(list.get(position).getCreatedAt().getTime(), System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS));
}

But as you can see I'm setting textView's text with hardcoded strings. Is this a good solution? Is there any more professional ways?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
kaya
  • 45
  • 6
  • One way to do that is you can use your own class instead of DateUtils.In that way you can also make it in Turkish language.check out this.. https://medium.com/@shaktisinh/time-a-go-in-android-8bad8b171f87 Hope this help you. – Maulik Togadiya Jul 13 '19 at 14:50

0 Answers0