Skip to content

Commit

Permalink
#2 - Feat: Util.date 추가(해당 년,월일의 마지막 day 구하기, 해당 일자의 시작/종료일시 구하기 메서드)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahah525 committed Oct 30, 2022
1 parent 33a5aaf commit 8054f5b
Showing 1 changed file with 31 additions and 0 deletions.
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);
}
}
}

0 comments on commit 8054f5b

Please sign in to comment.