Skip to content

Commit

Permalink
#2 - Feat: Ut 에 String <-> LocalDateTime 변환 메서드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ahah525 committed Nov 1, 2022
1 parent b94daa3 commit 063ba50
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;

public class Ut {
Expand All @@ -27,5 +28,25 @@ public static LocalDateTime getEndOfDay(int year, int month, int day) {
LocalDate date = LocalDate.of(year, month, day);
return date.atTime(LocalTime.MAX);
}

// 날짜 문자열 -> 해당 패턴의 LocalDateTime 변환
public static LocalDateTime parse(String pattern, String dateText) {
return LocalDateTime.parse(dateText, DateTimeFormatter.ofPattern(pattern));
}

// 날짜 문자열 -> 디폴트 패턴의 LocalDateTime 변환
public static LocalDateTime parse(String dateText) {
return parse("yyyy-MM-dd HH:mm:ss.SSSSSS", dateText);
}

// 해당 패턴의 LocalDateTime -> 날짜 문자열 변환
public static String format(String pattern, LocalDateTime datetime) {
return datetime.format(DateTimeFormatter.ofPattern(pattern));
}

// 디폴트 패턴의 LocalDateTime -> 날짜 문자열 변환
public static String format(LocalDateTime datetime) {
return format("yyyy-MM-dd HH:mm:ss.SSSSSS", datetime);
}
}
}

0 comments on commit 063ba50

Please sign in to comment.