I want my time duration to have the following format:
* hours and * minutes ago
But i’m only getting <* hours ago> each time.
What do i need to do to get the minutes in there?
I see now that when the duration is less than an hour, it is formatted in minutes but when it’s > 1 hour, it’s formatted in hours without minutes. But i want also when the duration is > 1 hour, to see the minutes.
Hi, currently in order to do what you ask, you’ll need to use:
PrettyTime p = new PrettyTime();
p.setUnits(new Hour(), new Minute());
List<Duration> durations = p.calculatePreciseDuration(myDate);
Then you’ll have to format each duration:
List<String> formatted = new ArrayList();
for(Duration d : durations)
Then just join your elements:
String result = Strings.join(formatted, "and")
Using something like this:
* @author <a href="mailto:email@example.com">Lincoln Baxter, III</a>
public abstract class Strings
* Join a collection of strings using the given delimeter.
public static String join(final Collection<?> collection, final String delimiter)
StringBuffer buffer = new StringBuffer();
Iterator<?> iter = collection.iterator();
Viewing 2 posts - 1 through 2 (of 2 total)
The forum ‘PrettyTime Users’ is closed to new topics and replies.
Comments are closed.
Do you play Magic?
Get TopDecked MTG, the #1 Magic App, built by players, for players. Free to use, forever.