====== DateFormat format() ====== * description : DateFormat format() * author : 오션 * email : shlim@repia.com * lastupdate : 2022-06-21 Tue \\ ====== DateFormat format() ====== ==== Ref LInk ==== [[https://www.geeksforgeeks.org/dateformat-format-method-in-java-with-examples/|DateFormat format() Method in Java with Examples]]\\ \\ ===== 설명(구글 번역기) ===== java.text 패키지 내부에 있는 DateFormat 클래스는 모든 로케일의 날짜를 형식화하고 구문 분석하는 데 사용되는 추상 클래스입니다.\\ 날짜를 텍스트로 형식을 지정하고 텍스트를 날짜로 구문 분석할 수 있습니다.\\ DateFormat 클래스는 기본 날짜/시간을 획득, 형식화, 구문 분석하는 많은 기능을 제공합니다.\\ DateFormat 클래스는 Format 클래스의 하위 클래스임을 의미하는 Format 클래스를 확장합니다.\\ 따라서 DateFormat 클래스는 추상 클래스이므로 언어 독립적인 방식으로 날짜 또는 시간을 형식화하고 구문 분석하는 날짜/시간 형식화 하위 클래스에 사용할 수 있습니다.\\ Java에서 DateFormat 클래스의 format() 메소드는 주어진 날짜를 날짜/시간 문자열로 형식화하는 데 사용됩니다.\\ 기본적으로 이 방법은 이 날짜와 시간을 mm/dd/yyyy와 같은 특정 형식으로 변환하는 데 사용됩니다.\\ \\ import java.text.DateFormat; import java.util.Calendar; public class GFG { public static void main(String[] args) { // Initializing the first formatter DateFormat DFormat = DateFormat.getDateInstance(); // Initializing the calendar Object Calendar cal = Calendar.getInstance(); // Displaying the actual date System.out.println("Output:: The original Date: " + cal.getTime()); // Output:: The original Date: Tue Jun 21 19:14:40 KST 2022 // Converting date using format() method String currentDate = DFormat.format(cal.getTime()); // Pringing the formatred date System.out.println("Output:: Formatted Date: " + currentDate); // Output:: Formatted Date: 2022. 6. 21. } } \\ \\ import java.text.DateFormat; import java.util.Calendar; import java.util.Locale; public class GFG2 { public static void main(String[] args) { // Initializing the first formatter DateFormat DFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, Locale.getDefault()); // Initializing the calendar Object Calendar cal = Calendar.getInstance(); // Displaying the actual date System.out.println("The original date is " + cal.getTime()); // The original date is Tue Jun 21 19:26:05 KST 2022 // Converting date using format() method and storing date in a string String nowDate = DFormat.format(cal.getTime()); // Formatted Date is 2022년 6월 21일 오후 7시 26분 5초 KST // Printing the formatted date on console System.out.println("Formatted Date is " + nowDate); } } \\ ===== Reference ===== * Calendar 클래스의 주요 메소드 static Calendar getInstance() : 현재 날짜와 시간 정보를 가진 Calendar 객체를 생성한다. void setTime(Date date) : date 객체의 날짜와 시간 정보를 현재 객체로 생성한다. \\ * Calendar 클래스의 주요 상수 Calendar.DATE : 현재 월의 날짜 ==== Ref Link ==== [[https://moonong.tistory.com/10|Calendar 클래스의 개념과 예제(Calendar class in java)]]\\ {{tag> 오션, DateFormat format()}}