- 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
LocalDateTime range() method in Java
The range of values for a ChronoField can be obtained using the range() method in the LocalDateTime class in Java. This method requires a single parameter i.e. the ChronoField for which the range of values is required and it returns the range of values.
A program that demonstrates this is given as follows −
Example
import java.time.*; import java.time.temporal.ChronoField; import java.time.temporal.ValueRange; public class Main { public static void main(String[] args) { LocalDateTime ldt = LocalDateTime.parse("2019-02-18T11:19:50"); System.out.println("The LocalDateTime is: " + ldt); ValueRange dowRange = ldt.range(ChronoField.DAY_OF_WEEK); System.out.println("The range of DAY_OF_WEEK: " + dowRange); } }
Output
The LocalDateTime is: 2019-02-18T11:19:50 The range of DAY_OF_WEEK: 1 - 7
Now let us understand the above program.
First the LocalDateTime is displayed. Then the range of values of a particular ChronoField are obtained using the range() method and displayed. A code snippet that demonstrates this is as follows −
LocalDateTime ldt = LocalDateTime.parse("2019-02-18T11:19:50"); System.out.println("The LocalDateTime is: " + ldt); ValueRange dowRange = ldt.range(ChronoField.DAY_OF_WEEK); System.out.println("The range of DAY_OF_WEEK: " + dowRange);
Advertisements