如何在Android开发中自定义日期格式,使其类似于Twitter和Instagram。下面是我当前的代码,但我不喜欢它产生的格式,例如“11分钟前”或“34分钟前”。我更喜欢Twitter的格式,例如“11m”或“34m”。请问有人知道我如何将我的日期格式化为这样吗?
Date createdAt = message.getCreatedAt();//get the date the message was created from parse backend
long now = new Date().getTime();//get current date
String convertedDate = DateUtils.getRelativeTimeSpanString(
createdAt.getTime(), now, DateUtils.SECOND_IN_MILLIS).toString();
mPostMessageTimeLabel.setText(convertedDate); //sets the converted date into the message_item.xml view
if(timeElapsed> oneWeek)
,因为在这种情况下它实际上总是超过一周。 - sembozdemir