To define a duration, sometimes we just write below
long thirtyMinutes = 30 * 60 * 1000; // In Miliseconds
As of Java 8 with the java.time framework, we could make it more elegant using
long thirtyMinutes = Duration.ofMinutes(30).toMillis();
But as I'm still in Java 7 (Android), I can't use java.time.Duration. So is there anyway I could have it define as elegant as Java 8, instead of just ruing the multiplication equation above?
Without a backported library- java.util.concurrent.TimeUnit
//convert 4 hours to milliseconds
long ms = TimeUnit.Hours.toMillis(4);
Similar for minutes, days, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With