자바 요일구하기
자바에서 요일(day of week)을 구하는 간단한 방법
(원문:http://www.leveluplunch.com/java/examples/get-day-of-week/)
Java Calendar
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH, Calendar.APRIL);
cal.set(Calendar.DAY_OF_MONTH, 4);
cal.set(Calendar.YEAR, 2016);
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
assertEquals(Calendar.FRIDAY, dayOfWeek);
Java 8
LocalDate date = LocalDate.of(2016, Month.APRIL, 4);
DayOfWeek dayOfWeek = date.getDayOfWeek();
assertEquals(DayOfWeek.FRIDAY, dayOfWeek);
또는
int dayOfWeek2 = dayOfWeek.get(ChronoField.DAY_OF_WEEK);
assertEquals(DayOfWeek.FRIDAY.getValue(), dayOfWeek2);
또는
LocalDateTime localDateTime = LocalDateTime.of(2016, Month.APRIL, 4, 5, 4);
DayOfWeek dayOfWeek3 = localDateTime.getDayOfWeek();
assertEquals(DayOfWeek.FRIDAY, dayOfWeek3);
Joda Time
DateTime dateTime = new DateTime(2016, 4, 4, 0, 0);
int dayOfWeek = dateTime.getDayOfWeek();
assertEquals(DateTimeConstants.FRIDAY, dayOfWeek);
Old JDK
출처: https://springboot.tistory.com/42?category=620230 [스프링부트는 사랑입니다]
'Spring Framework > Spring boot' 카테고리의 다른 글
BeanNameGenerator로 Restful API 버전 관리 (0) | 2020.09.03 |
---|---|
Stopwatch Class는 무슨일을 할까? 그리고 메소드 네이밍과 책임. (0) | 2020.09.03 |
SpringBoot Actuator BeansEndPoint Class (0) | 2020.09.03 |
Spring Boot SpringApplication Class (0) | 2020.09.03 |
스프링 비동기와 자바8의 CompletableFuture (0) | 2020.09.03 |
스프링에서 @Async로 비동기처리하기 @Async in Spring (0) | 2020.09.03 |
스프링부트 : REST 어플리케이션에서 예외처리하기 (0) | 2020.09.03 |
스프링 부트에서 @ControllerAdvice를 활용한 전역 예외처리 (0) | 2020.09.03 |