![]() |
In Java, when working with time-related data, we may need to format seconds to make it a more human-readable representation. In this article, we will see how to format seconds in Java. Example of
SyntaxThe formatting can be achieved using Duration and Period classes from java.time package introduced in Java 8. String formattedTime = Duration.ofSeconds(seconds) Program to Format Seconds in JavaBelow is the implementation of Format Seconds in Java: Java
Output
Formatted Time: 1h 1m 5s Explanation of the Program:In the above program,
|
Reffered: https://www.geeksforgeeks.org
Java |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |