- import org.apache.commons.lang.time.DurationFormatUtils;
- //...
- Date startTime = new Date();
- //...
- //... lengthy jobs
- //...
- Date endTime = new Date();
- long diff = endTime.getTime() - startTime.getTime();
- String hrDateText = DurationFormatUtils.formatDuration(diff, "d 'day(s)' H 'hour(s)' m 'minute(s)' s 'second(s)' ");
- System.out.println("Duration : " + hrDateText);
Sample Output the code:
0 days(s) 0 hour(s) 0 minute(s) 1 second(s)
Maven dependency:
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- <version>3.3.2</version>
- </dependency>
No comments:
Post a Comment