タイムスタンプを含む文字列をアンドロイドの RelativeDateTimeString と一致する時間に変換しようとしているので、相対時間としてフォーマットできます。取得するタイムスタンプは次の形式です。
2011-08-17 04:57:38
その文字列を取得して、ここで相対時間関数に渡したいと思います。
public void RelativeTime(Long time){
String str = (String) DateUtils.getRelativeDateTimeString(
this, // Suppose you are in an activity or other Context subclass
time, // The time to display
DateUtils.SECOND_IN_MILLIS, // The resolution. This will display only minutes
// (no "3 seconds ago"
DateUtils.WEEK_IN_MILLIS, // The maximum resolution at which the time will switch
// to default date instead of spans. This will not
// display "3 weeks ago" but a full date instead
0); // Eventual flags
toast(str);
}
したがって、関数は「2日前」などのトーストを表示する必要があります.
編集: 申し訳ありませんが、私も書いたトースト機能があります。
public void toast(String text){
Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
}