-1

I want to calculate time difference of my script execution in java in HH:MM:SS format

I am able to get time in HH:mm:ss by below code but unable to calculate the difference

LocalTime time = LocalTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
        String StartTime = time.format(formatter);
        System.out.println(StartTime);

Unable to calculate difference , please share some code to calculate difference in HH:mm:ss

seenukarthi
  • 8,241
  • 10
  • 47
  • 68
Rohit
  • 23
  • 5
  • More specifically [this answer](https://stackoverflow.com/a/34541535/9223839) that uses java 8 – Joakim Danielson Sep 06 '19 at 18:45
  • Tip: Reporting a span-of-time as a time-of-day leads to confusion and errors. I suggest instead you use the standard [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601#Durations) format, or something similar. `Duration.ofMillis( milliseconds ).toString()` – Basil Bourque Sep 06 '19 at 19:37
  • thanks , this worked . – Rohit Sep 09 '19 at 15:52

1 Answers1

0

Use Duration class: Duration.of method

  • Usually we expect a bit more than this in an Answer on Stack Overflow. Some discussion and a bit of sample code would help. I have done just that for `Duration` on [my Answer](https://stackoverflow.com/a/57827578/642706) on the original Question of this duplicate. – Basil Bourque Sep 06 '19 at 19:34