0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

データの鮮度にフォーカスした時間表示形式

Posted at

メルカリやtwitterなどの時刻表示形式を実装する

サマリ

タイムラインなど、実際の時刻より現在時刻との差分が重視される時間表示を行う

ポイントとして、ある程度の敷居値で単位を秒、分、時間、日で区切って切り上げた上で表示を行う

コード


String timeDiffView(int timeDiff) {
  String buff4Return = "0秒前";

  if (timeDiff < 60 * 1000) {
    buff4Return = (timeDiff / 1000).floor().toString() + "秒前";
  } else if (timeDiff < 60 * 60 * 1000) {
    buff4Return = (timeDiff / 1000 / 60).floor().toString() + "分前";
  } else if (timeDiff < 24 * 60 * 60 * 1000) {
    buff4Return = (timeDiff / 1000 / 60 / 60).floor().toString() + "時間前";
  } else {
    buff4Return = (timeDiff / 1000 / 60 / 60 / 24).floor().toString() + "日前";
  }

  return buff4Return;
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?