toMillisInt()
is a DurationUtils
used to convert the duration to milliseconds bound to an int
datatype rather than a long
datatype.
DurationUtils
The definition of DurationUtils
can be found in the Apache Commons Lang
package, which we can add to the Maven project by adding the following dependency to the pom.xml
file:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
For other versions of the commons-lang package, refer to the Maven Repository.
You can import the DurationUtils
class as follows:
import org.apache.commons.lang3.time.DurationUtils;
public static int toMillisInt(final Duration duration)
final Duration duration
: The duration object to convert.This method returns milliseconds as an integer.
In the code below, we convert the Duration
object to milliseconds with the help of toMillisInt()
method.
import org.apache.commons.lang3.time.DurationUtils;import java.time.Duration;public class Main{public static void main(String[] args) {Duration duration = Duration.ofDays(3);System.out.printf("DurationUtils.toMillisInt(%s) = %s", duration, DurationUtils.toMillisInt(duration));System.out.println();}}
The output of the code will be as follows:
DurationUtils.toMillisInt(PT72H) = 259200000