-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2 - Feat: Util.date 추가(해당 년,월일의 마지막 day 구하기, 해당 일자의 시작/종료일시 구하기 메서드)
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
3Week_Mission/mutbooks/src/main/java/com/example/mutbooks/util/Ut.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.example.mutbooks.util; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.time.LocalTime; | ||
import java.util.Calendar; | ||
|
||
public class Ut { | ||
public static class date { | ||
|
||
// 해당 년, 월의 마지막 일자 구하기 | ||
public static int getEndDay(int year, int month) { | ||
Calendar cal = Calendar.getInstance(); | ||
cal.set(year, month - 1, 1); | ||
|
||
return cal.getActualMaximum(Calendar.DAY_OF_MONTH); | ||
} | ||
|
||
// 해당 일자의 시작일시 구하기 | ||
public static LocalDateTime getStartOfDay(int year, int month, int day) { | ||
LocalDate date = LocalDate.of(year, month, day); | ||
return date.atStartOfDay(); | ||
} | ||
|
||
// 해당 일자의 종료일시 구하기 | ||
public static LocalDateTime getEndOfDay(int year, int month, int day) { | ||
LocalDate date = LocalDate.of(year, month, day); | ||
return date.atTime(LocalTime.MAX); | ||
} | ||
} | ||
} |