【发布时间】:2011-05-24 16:36:04
【问题描述】:
我的日期格式如下:
String inputDateString = aMessage.getString("updated_at");
DateTimeFormatter fmt = ISODateTimeFormat.dateTimeNoMillis();
DateTime date = fmt.parseDateTime(inputDateString);
DateTime now = new DateTime();
Period period = new Period(date, now);
PeriodFormatter formatter = new PeriodFormatterBuilder()
.appendSeconds().appendSuffix(" seconds ago\n")
.printZeroNever()
.toFormatter();
String elapsed = formatter.print(period);
dateTextView.setText(elapsed);
我希望能够展示:
3 seconds ago if the period is less than 60 seconds
3 minutes ago if the period is less than 60 minutes
3 hours ago is the period is less than X hours
3 days ago if the period is less than X days
等等。等等
我怎样才能做到这一点?
【问题讨论】:
标签: java datetime date time jodatime