tags:

views:

227

answers:

2

Is there a way to convert milliseconds to minutes using java.util.concurrent.TimeUnit?

This answer seems to suggest that you can use a TimeUnit.MILLISECONDS.toMinutes() method, and the documentation suggests that you could use the TimeUnit.MILLISECONDS.convert() method with TimeUnit.MINUTES - the problem is that neither TimeUnit.MINUTES or TimeUnit.MILLISECONDS.toMinutes() seem to actually exist.

Am I missing something here?

+1  A: 

All you need to do from ms to minutes is divide by 60000. Why not just do that>

bwawok
Because it is easy to screw up, by say, typing 600000, and using TimeUnit makes it clear what dividing by 60000 is supposed to be doing.
Mayra
You can do the division by (60 * 1000), which makes it clearer.
James Van Huis
Yeah, I've resorted to doing doing it milliseconds / (60 * 1000) style. But I'm doing this for lots of units (I'm going from milliseconds to minutes, days, hours and weeks) so if there was a prettier way to do it I would prefer it.
russell_h
If you're doing it a lot, write your own utility methods (in the style of TimeUnit), rather than having `(60 * 1000)` all over the place.
Christopher
+1  A: 

I believe TimeUnit might have added minutes in 1.6: 1.6 docs, 1.5 docs

Mayra
Assuming this is about Android, that doesn't help. It seems to be based on the 1.5 APIs.
Christopher
True, but it does explain the discrepancy. Probably in Android need to implement your own extension.
Mayra
Ah, you're very right. When the linked comment referred to '1.6' I assume it meant Android 1.6 - I probably should have known that. Thanks!
russell_h