Java Reference
In-Depth Information
Constants for some datetime fields that are specific to the isO-8601 calendar system are declared in the
IsoFields class. For example, IsoFields.DAY_OF_QUARTER represents isO-8601 based day-of-quarter.
Tip
The following snippet of code demonstrates how to use a ChronoField to extract a field value from a datetime
and whether the datetime supported the field:
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.ChronoField;
...
LocalDateTime now = LocalDateTime.now();
System.out.println("Current Date Time: " + now);
System.out.println("Year: " + now.get(ChronoField.YEAR));
System.out.println("Month: " + now.get(ChronoField.MONTH_OF_YEAR));
System.out.println("Day: " + now.get(ChronoField.DAY_OF_MONTH));
System.out.println("Hour-of-day: " + now.get(ChronoField.HOUR_OF_DAY));
System.out.println("Hour-of-AMPM: " + now.get(ChronoField.HOUR_OF_AMPM));
System.out.println("AMPM-of-day: " + now.get(ChronoField.AMPM_OF_DAY));
LocalDate today = LocalDate.now();
System.out.println("Current Date : " + today);
System.out.println("LocalDate supports year: " + today.isSupported(ChronoField.YEAR));
System.out.println("LocalDate supports hour-of-day: " + today.isSupported(ChronoField.HOUR_OF_DAY));
System.out.println("Year is supported by LocalDate: " + ChronoField.YEAR.isSupportedBy(today));
System.out.println("Hour-of-day is supported by LocalDate: " +
ChronoField.HOUR_OF_DAY.isSupportedBy(today));
Current Date Time: 2014-03-01T10:15:24.918
Year: 2014
Month: 3
Day: 1
Hour-of-day: 10
Hour-of-AMPM: 10
AMPM-of-day: 0
Current Date : 2014-03-01
LocalDate supports year: true
LocalDate supports hour-of-day: false
Year is supported by LocalDate: true
Hour-of-day is supported by LocalDate: false
The value for the AMPM_OF_DAY field can be 0 or 1; 0 indicates AM and 1 indicates PM.
 
Search WWH ::




Custom Search