Java Date Time - Duration toMillis() example








Duration toMillis() converts this duration to the total length in milliseconds.

Syntax

toMillis has the following syntax.

public long toMillis()

Example

The following example shows how to use toMillis.

import java.time.Duration;
import java.time.LocalTime;
/*w ww  .  ja va 2 s . c o m*/
public class Main {
  public static void main(String[] args) {
    Duration duration = Duration.between(LocalTime.MIDNIGHT,LocalTime.NOON);
    System.out.println(duration.toMillis());
    
  }
}

The code above generates the following result.