Calendar

    [Java] 날짜와 시간(Date, Calendar 클래스) & 형식(Format 클래스)

    [Java] 날짜와 시간(Date, Calendar 클래스) & 형식(Format 클래스)

    📌Date 클래스 Date는 날짜를 표현하는 클래스이다. Date() 생성자는 컴퓨터의 현재 날짜를 읽어 Date 객체로 만든다. 현재 날짜를 문자열로 얻고 싶다면 toString() 메소드를 사용하면 된다. toString() 메소드는 영문으로 날짜를 리턴하기 때문에 만약에 한글로 출력하고 싶다 던지 혹은 다른 문자열 포맷으로 얻고 싶다면 java.text.SimpleDateFormat 클래스를 이용하면 된다. Date now = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy 년 MM월 dd일 hh시 mm분 ss초"); String strNow = sdf.format(now); System.out.println(strNow); //2022..