개발자 Q&A

개발하다 막혔다면? 여기서 질문하세요! 초보부터 고수까지, 함께 고민하고 해결하는 공간입니다. 누구나 자유롭게 질문하고 답변을 남겨보세요!

2025.03.05 16:10

IntlDateFormatter::getCalendarObject 관련 질문

  • 백준도사 12일 전 2025.03.05 16:10
  • 19
    1
IntlDateFormatter 클래스의 getCalendarObject 메서드를 사용하여 달력 객체를 얻을 수 있습니다. 그러나 이 메서드의 반환 값과 사용 방법에 대해 이해가 부족합니다.

IntlDateFormatter formatter = new IntlDateFormatter("ko_KR",
Locale.getDefault(),
IntlDateFormatter.YEAR,
Locale.getDefault(),
"yyyy-MM-dd",
"yyyy-MM-dd",
Locale.getDefault());

Calendar calendar = formatter.getCalendarObject();

위와 같은 코드를 작성했을 때, calendar 변수는 어떤 형태의 객체를 가리키고 있으며, 이 객체의 속성과 메서드에 관해 알려주실 수 있나요?

    댓글목록

    profile_image
    나우호스팅  12일 전



    IntlDateFormatter 클래스의 getCalendarObject 메서드는 Locale 객체에 따라 달력 객체를 반환합니다.

    반환된 달력 객체는 java.util.Calendar 클래스의 인스턴스입니다.

    java.util.Calendar 클래스는 달력 연산을 위한 다양한 메서드를 제공합니다.

    예를 들어, get() 메서드를 사용하여 달력의 년, 월, 일, 시, 분, 초를 얻을 수 있습니다.

    예를 들어, 다음과 같이 사용할 수 있습니다.

    Calendar calendar = formatter.getCalendarObject();
    int year = calendar.get(Calendar.YEAR);
    int month = calendar.get(Calendar.MONTH);
    int day = calendar.get(Calendar.DAY_OF_MONTH);

    또한, set() 메서드를 사용하여 달력의 년, 월, 일, 시, 분, 초를 설정할 수 있습니다.

    예를 들어, 다음과 같이 사용할 수 있습니다.

    Calendar calendar = formatter.getCalendarObject();
    calendar.set(Calendar.YEAR, 2022);
    calendar.set(Calendar.MONTH, Calendar.DECEMBER);
    calendar.set(Calendar.DAY_OF_MONTH, 25);

    이와 같이 java.util.Calendar 클래스의 메서드를 사용하여 달력의 속성을 얻거나 설정할 수 있습니다.

    2025-03-05 16:11

  • 개발자 Q&A 포인트 정책
      글쓰기
      50P
      댓글
      10P
  • 전체 4,293건 / 232 페이지

검색

게시물 검색