Programming/Java
[JAVA] LocalDateTime 년월일 값만 출력
seandoesdev
2023. 11. 11. 04:27
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class LocalDateTimeExample {
public static void main(String[] args) {
// 현재 날짜와 시간 가져오기
LocalDateTime now = LocalDateTime.now();
// DateTimeFormatter를 사용하여 원하는 형식으로 포맷팅
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String formattedDate = now.format(formatter);
// 결과 출력
System.out.println("Formatted Date: " + formattedDate);
}
}
reference
https://stackoverflow.com/questions/1156468/how-to-format-a-java-sql-timestamp-for-displaying