Domanda

I want to print "1h" or "1d" or "1y" , ideally all my possible strings only take 3 characters ie "11h" or "11y"

All my objects have an epoch time and I convert that to a Calendar object

    Calendar calendar = new GregorianCalendar(Locale.getDefault());
    Date trialTime = new Date(time*1000);
    calendar.setTime(mTime);

But now I need to know how long ago that time was from now.

 long currentTime = System.currentTimeMillis();

If I get the different of the current time and the passed in time, then I'll just be stuck with a low epoch number, if I convert that to calendar object then I'll just have an arbitrarily old year.

My next hunch is to take that difference and determine how long of a time that is, does this use the date or datetime or calendar object for assistance?

any insight appreciated

È stato utile?

Soluzione

Joda-Time has the smarts that you need.

If you take the delta time in tics between your object times you can use Duration to get number of hours, days, etc.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top