Java Duration format to String like "2h0"

Description

Java Duration format to String like "2h0"

import java.time.Duration;

public class Main {
  public static void main(String[] argv) {
    System.out.println(displayDuration(Duration.ofHours(2)));
  }//from  w w  w.  j a  v a  2 s.  com

  public static String displayDuration(Duration tempsCourse) {
    return String.valueOf(tempsCourse.toHours() + "h") + String.valueOf(tempsCourse.toMinutes() % 60);
  }
}



PreviousNext

Related