Is there an easy way to use TimeUnit class to spec...
# getting-started
c
Is there an easy way to use TimeUnit class to specify 30 minutes for example? I found myself doing
val thirty_mins = 30 * 60_000
but there has to be a way to just do TimeUnit.Minutes(30) right?
v
You mean like
TimeUnit.MILLISECONDS.convert(30, TimeUnit.MINUTES)
or
TimeUnit.MINUTES.toMillis(30))
?
Or
30.minutes.inMilliseconds
?
l
Based on your example you probably looking for
Copy code
TimeUnit.MINUTES.toMillis(30)
v
Whoups, ms, changed my examples
t
kotlin.Duration is so pleasant compared to TimeUnit, too bad it's still experimental
n
if it's a JVM project I'd probably use the Java Duration class
v
Why don't you like
30.minutes.inMilliseconds
?
c
I didn't know that's a thing! Thanks!
m
what's to reason why this returns a double?Seems not to be the correct type for milliseconds. The same for days and all other units
v
Why not?
1500.microseconds.inMilliseconds
5.hours.inDays