Java Date Time - Duration toMinutes() example








Duration toMinutes() gets the number of minutes in this duration.

This returns the total number of minutes in the duration by dividing the number of seconds by 60.

Syntax

toMinutes has the following syntax.

public long toMinutes()

Example

The following example shows how to use toMinutes.

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

The code above generates the following result.