시간 필드는 월-오-분 또는 시와 같은 날짜-시간 필드입니다. 이러한 필드는 TemporalField 인터페이스로 표시되며 ChronoField 클래스는 이 인터페이스를 구현합니다.
다음은 ChronoField 클래스에서 지원하는 날짜와 관련된 다양한 시간적 필드의 목록입니다 -
| 필드 | 설명 |
|---|---|
| ALIGNED_DAY_OF_WEEK_IN_MONTH | 이 필드는 한 달의 요일을 나타냅니다. |
| ALIGNED_DAY_OF_WEEK_IN_YEAR | 이 필드는 1년의 정렬된 요일을 나타냅니다. |
| ALIGNED_WEEK_OF_MONTH | 이 필드는 한 달의 정렬된 부분을 나타냅니다. |
| ALIGNED_WEEK_OF_YEAR | 이 필드는 정렬된 주를 나타냅니다. |
| DAY_OF_MONTH | 이 필드는 날짜를 나타냅니다. |
| DAY_OF_WEEK | 이 필드는 요일을 나타냅니다. |
| DAY_OF_YEAR | 이 필드는 1년 중 일을 나타냅니다. |
| EPOCH_DAY | 이 필드는 한 해의 신기원을 나타냅니다. |
| ERA | 이 필드는 연도를 나타냅니다. |
| 연도 | 이 필드는 연도를 나타냅니다. |
| YEAR_OF_ERA | 이 필드는 연도를 나타냅니다. |
LocalDate 및 LocaldateTime 클래스의 get() 또는 getLong() 메서드는 임시 필드를 매개 변수로 받아 현재 개체에서 지정된 필드의 값을 가져옵니다.
예
import java.time.LocalDate;
import java.time.temporal.ChronoField;
public class Demo {
public static void main(String args[]) {
//Instantiating the LocalDate class
LocalDate lDate = LocalDate.now();
int field = lDate.get(ChronoField.DAY_OF_MONTH);
System.out.println("Day of the month: "+field);
field = lDate.get(ChronoField.DAY_OF_WEEK);
System.out.println("Day of the month: "+field);
field = lDate.get(ChronoField.DAY_OF_YEAR);
System.out.println("Day of the month: "+field);
long epoch = lDate.getLong(ChronoField.EPOCH_DAY);
System.out.println("Day of the month: "+epoch);
field = lDate.get(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH);
System.out.println("Week in the month: "+field);
field = lDate.get(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR);
System.out.println("Day of the week in an year: "+field);
field = lDate.get(ChronoField.ERA);
System.out.println("Era: "+field);
}
} 출력
Day of the month: 11 Day of the month: 3 Day of the month: 316 Day of the month: 18577 Week in the month: 4 Day of the week in an year: 1 Era: 1
예
import java.time.DayOfWeek;
import java.time.LocalTime;
import java.time.Month;
import java.time.Year;
import java.time.temporal.ChronoField;
public class Demo {
public static void main(String args[]) {
//Instantiating the LocalDateTime class
LocalTime lTime = LocalTime.now();
System.out.println(lTime);
int field = Year.of(2019).get(ChronoField.YEAR);
System.out.println("Year: "+field);
field = Month.of(8).get(ChronoField.MONTH_OF_YEAR);
System.out.println("Year: "+field);
field = DayOfWeek.of(3).get(ChronoField.DAY_OF_WEEK);
System.out.println("Year: "+field);
}
} 출력
20:01:43.171 Year: 2019 Year: 8 Year: 3