如何将时间转换为“时间之前在Android中 [英] How to convert time to " time ago " in android
问题描述
我的服务器.返回时间:
My server. It return time :
"2016-01-24T16:00:00.000Z"
我想要
1:转换为字符串.
2:从服务器加载时,我希望它显示"time ago".
2 : I want it show " time ago " when load it from server.
请.救救我!
推荐答案
我主要看到三种方式:
a)使用 b)外部库 ocpsoft/PrettyTime (基于 在这里,您还必须使用 Here you have to use 在应用程序的lib下面导入 import below lib in your app c)使用我的库 Time4A (重量级,但具有最好的i18n支持) c) using my library Time4A (heavyweight but with best i18n-support) 这篇关于如何将时间转换为“时间之前在Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!SimpleDateFormat
和
java.util.Date
)SimpleDateFormat
来生成time
结果作为对"2016-01-24T16:00:00.000Z"的解释.SimpleDateFormat
, too, to produce the time
-result as interpretation of "2016-01-24T16:00:00.000Z".implementation 'org.ocpsoft.prettytime:prettytime:4.0.1.Final'
PrettyTime prettyTime = new PrettyTime(Locale.getDefault());
String ago = prettyTime.format(new Date(time));
Moment moment = Iso8601Format.EXTENDED_DATE_TIME_OFFSET.parse("2016-01-24T16:00:00.000Z");
String ago = PrettyTime.of(Locale.getDefault()).printRelativeInStdTimezone(moment);