Best way to format a date relative to now on Android

前端 未结 10 1713
隐瞒了意图╮
隐瞒了意图╮ 2021-01-31 15:57

I am creating a feature in an Android app to get an arbitrary date (past, present or future) and find the difference relative to now.

Both my now and

10条回答
  •  别那么骄傲
    2021-01-31 16:39

    for Android you can use most simple way with Joda-Time-Android library:

    Date yourTime = new Date();
    DateTime dateTime = new DateTime(yourTime); //or simple DateTime.now()
    final String result = DateUtils.getRelativeTimeSpanString(getContext(), dateTime);
    

提交回复
热议问题