-3

I need format java.time.Duration like

T05:00:00 (hours:minutes:seconds). 

How can I do it?

nircraft
  • 8,242
  • 5
  • 30
  • 46
nikita21
  • 29
  • 3

2 Answers2

0

If you could convert to a string you can use

String.format();

for this.

Willey3x37
  • 310
  • 2
  • 12
0

The SimpleDateFormat class is within Java's utility library and it is what most people use:

import java.text.SimpleDateFormat;
import java.util.Date;

public class Time {

public static void main(String[] args) {

      //instance of the time, date      
      Date date = new Date();
      //format it however you like.
      String strDateFormat = "HH:mm:ss";
      //The SimpleDateFormat class allows the actual time format
      SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);
      //use the sdf object to format
      System.out.println(sdf.format(date));


    }

}
MGT
  • 173
  • 12