如何用joda时间SQLite计算经过的时间

时间:2016-02-23 06:05:47

标签: android database sqlite

我如何处理我的数据库日期= 1456201899566(getTimeInMillis),我想从现在开始经过joda时间。谢谢你,抱歉我的英文不好

1 个答案:

答案 0 :(得分:0)

您可以使用here

中的PeriodFormatter .Source
 Date mydate = new Date(TimeInMillis);//TimeInMillis is your value from database
 DateTime mystartDate = new DateTime(mydate);

 //DateTime mystartDate = new DateTime(1978, 3, 26, 12, 35, 0, 0);
 DateTime now = new DateTime();
 Period period = new Period(mystartDate , now);

 PeriodFormatter formatter = new PeriodFormatterBuilder()
.appendSeconds().appendSuffix(" seconds ago\n")
.appendMinutes().appendSuffix(" minutes ago\n")
.appendHours().appendSuffix(" hours ago\n")
.appendDays().appendSuffix(" days ago\n")
.appendWeeks().appendSuffix(" weeks ago\n")
.appendMonths().appendSuffix(" months ago\n")
.appendYears().appendSuffix(" years ago\n")
.printZeroNever()
.toFormatter();

String elapsed = formatter.print(period);