- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 4336 Articles for Java 8
3K+ Views
The value of a duration in seconds can be obtained using the getSeconds() method in the Duration class in Java. This method requires no parameters and it returns the duration value in seconds.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo { public static void main(String[] args) { Duration d = Duration.ofMinutes(5); System.out.println("The duration is: " + d); System.out.println("The duration in seconds is: " + d.getSeconds()); } }OutputThe duration is: PT5M The duration in seconds is: 300Now let us understand the above program.The ... Read More
25 Views
An immutable copy of a LocalTime with the hour altered as required is done using the method withHour() in the LocalTime class in Java. This method requires a single parameter i.e. the hour that is to be set in the LocalTime and it returns the LocalTime with the hour altered as required.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Main { public static void main(String[] args) { LocalTime lt1 = LocalTime.parse("23:15:30"); System.out.println("The LocalTime is: " + lt1); LocalTime lt2 = lt1.withHour(5); ... Read More
37 Views
An immutable copy of a LocalTime with the minutes altered as required is done using the method withMinute() in the LocalTime class in Java. This method requires a single parameter i.e. the minute that is to be set in the LocalTime and it returns the LocalTime with the minute altered as required.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Main { public static void main(String[] args) { LocalTime lt1 = LocalTime.parse("23:15:30"); System.out.println("The LocalTime is: " + lt1); LocalTime lt2 = lt1.withMinute(45); ... Read More
46 Views
It can be checked if a ChronoUnit is supported by the LocalTime class or not by using the isSupported() method in the LocalTime class in Java. This method requires a single parameter i.e. the ChronoUnit to check. It returns true if the ChronoUnit is supported by the LocalTime class and false otherwise.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.time.temporal.*; public class Demo { public static void main(String[] args) { LocalTime lt = LocalTime.now(); System.out.println("The LocalTime is: " + lt); boolean flag = lt.isSupported(ChronoUnit.HOURS); ... Read More
170 Views
An immutable copy of a LocalTime where the required duration is subtracted from it can be obtained using the minus() method in the LocalTime class in Java. This method requires two parameters i.e. the duration to be subtracted and the TemporalUnit of the duration. Also, it returns the LocalTime object with the required duration subtracted from it.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.time.temporal.*; public class Demo { public static void main(String[] args) { LocalTime lt = LocalTime.now(); System.out.println("The LocalTime is: " + lt); ... Read More
153 Views
An immutable copy of a LocalTime where the required duration is added to it can be obtained using the plus() method in the LocalTime class in Java. This method requires two parameters i.e. the duration to be added and the TemporalUnit of the duration. Also, it returns the LocalTime object with the required duration added to it.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.time.temporal.*; public class Demo { public static void main(String[] args) { LocalTime lt = LocalTime.now(); System.out.println("The LocalTime is: " + lt); ... Read More
99 Views
The LocalTime instance can be obtained from a string value using the parse() method in the LocalTime class in Java. This method requires a single parameter i.e. the string which is to be parsed. This string cannot be null. Also, it returns the LocalTime instance obtained from the string value that was passed as a parameter.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo { public static void main(String[] args) { LocalTime lt = LocalTime.parse("23:15:30"); System.out.println("The LocalTime is: " + lt); } }OutputThe LocalTime is: 23:15:30Now ... Read More
35 Views
The LocalTime object can be queried as required using the query method in the LocalTime class in Java. This method requires a single parameter i.e. the query to be invoked and it returns the result of the query.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.time.temporal.*; public class Demo { public static void main(String[] args) { LocalTime lt = LocalTime.parse("23:15:30"); System.out.println("The LocalTime is: " + lt); String precision = lt.query(TemporalQueries.precision()).toString(); System.out.println("The Precision for the LocalTime is: "+ precision); } }OutputThe LocalTime ... Read More
73 Views
The value of a particular duration in the number of nanoseconds can be obtained using the toNanos() method in the Duration class in Java. This method requires no parameters and it returns the duration in the number of nanoseconds.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo { public static void main(String[] args) { Duration d = Duration.ofSeconds(1); System.out.println("The duration is: " + d); System.out.println("The number of nanoseconds in the duration is: " + d.toNanos()); } }OutputThe duration is: PT1S The number of ... Read More
107 Views
The value of a particular duration in the number of milliseconds can be obtained using the toMillis() method in the Duration class in Java. This method requires no parameters and it returns the duration in the number of milliseconds.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo { public static void main(String[] args) { Duration d = Duration.ofSeconds(1); System.out.println("The duration is: " + d); System.out.println("The number of milliseconds in the duration is: " + d.toMillis()); } }OutputThe duration is: PT1S The number of ... Read More