태터데스크 관리자

도움말
닫기
적용하기   첫페이지 만들기

태터데스크 메시지

저장하였습니다.

java.util.Calendar

JAVA/Basic 2008/10/17 21:56
======================
java.util.Calendar Class
======================

1970년 1월1일을 기준으로 날짜와 시간에 대해 조작을 가능하도록 해주는 추상 클래스...
Calendar 클래스의 인스턴스를 얻기 위해서는  getInstance() 메소드를 이용하며 방법은 아래와 같습니다.

Calendar myCal = Calendar.getInstance();

이렇게 얻어진 myCal 객체는 현재 시스템의 날자와 시간이 초기화 되어 있는데... Calendar 클래스의
메소드는 다음과 같은 것들이 있습니다.

boolean after(Object when) : 현재 Calendar 객체가 인자인 when 객체보다 이후 시간이라면 true
boolean before(Object when) : 현재 Calendar 객체가 인자인 when 객체보다 이전 시간이라면 true
int get(int field) : field의 값(년, 월, 일, 시, 분, 초)의 값을 Return
getInstance() : default Time Zone과 Locale 정보를 이용해 Calendar 객체를 생성 반환
set(int year, int month, int date) : 현재 Calendar 객체의 필드중 인자로 넘어오는 값을 Set

Calendar 객체의 주요 상수들

AM_PM : AM인 경우 0, PM인 경우 1 반환
DAY_OF_MONTH : 1~31사이의 수, 한달중 날짜의 수
DAY_OF_WEEK : 요일을 나타내는 상수(일요일:1~7)
DAY_OF_YEAR : 한해중 몇일째인지
HOUR : AM. PM의 의미가 없이 단지 0~12시를 나타냄
MONTH : 달을 나타내는 상수(1월은 0)
WEEK_OF_MONTH : 한달중 몇째 주인지...
WEEK_OF_YEAR : 일년중 몇째 주인지...

[예제]
import java.util.Calendar;
import static java.lang.System.out;

public class CalendarExam {
    public static void main(String[] args) {
        Calendar cal = Calendar.getInstance();
       
        int week_of_year = cal.get(Calendar.WEEK_OF_YEAR);
        int week_of_month = cal.get(Calendar.WEEK_OF_MONTH);
        int yy = cal.get(Calendar.YEAR);
        int mm = cal.get(Calendar.MONTH)+1;  //1월이 0 이므로...
        int dd = cal.get(Calendar.DAY_OF_MONTH);
       
        out.println("오늘은 일년중 " + week_of_year + "째 주 입니다.");
        out.println("오늘은 " + mm + "월의  " + week_of_month + "째 주 입니다.");
        out.println("오늘은 " + yy + "년 " + mm + "월 " + dd + "일 입니다.");
    }
}
top

Trackback Address :: http://www.ssial.com/trackback/118 관련글 쓰기

  1. Chanel Outlet 2011/09/17 21:38 댓글주소 | 수정/삭제 | 댓글

    Time is what you make of it.

  2. Burberry Bags 2011/10/13 17:10 댓글주소 | 수정/삭제 | 댓글

    I'm happy I found this blog! From time to time students want to cognitive the keys of productive literary essays composing. Your first-class knowledge about this good post can become a proper basis for such people. Thanks.

  3. Coach Outlet Online 2011/11/15 12:52 댓글주소 | 수정/삭제 | 댓글

    I'm happy I found this blog ! It's very good and thank you for sharing it !

  4. The Bears dropped their http://www.moncler2u.co.uk/ second ht 2011/12/10 11:59 댓글주소 | 수정/삭제 | 댓글

    The Bears dropped their http://www.moncler2u.co.uk/ second http://www.monclerbransondoudoune.fr/doudoune-moncler-2011-c-11.html straight after winning five in a row, but http://www.monclerdoudounepascher2011.com/moncler-veste-c-24.html the biggest loss Sunday came in the http://www.monclersole.com/moncler-vest-mens-c-6.html first quarter.Forte took a hit to http://www.monclersole.com/ the right knee http://www.monclerfronline.com/veste-moncler-femme-c-9.html from Derrick Johnson on a run for no gain http://www.monclerfronline.com/moncler-doudoune-femme-c-4.html deep in Chicago territory, another big http://www.imonclerdoudoune.com/ blow for a team contending in the NFC.Quarterback Jay Cutler http://www.imonclerdoudoune.com/moncler-doudoune-homme-c-5.html was already out http://www.imonclerdoudoune.com/ indefinitely after breaking his right thumb against San Diego on http://www.doudounemoncleralpin.com/ Nov. 20, and now, they might have to make do http://www.monclerstyle2011.com/moncler-jackets-women-c-3.htm without the league's http://www.monclerstyle2011.com/moncler-jackets-men-c-4.html third-leading rusher.In the fourth and http://www.monclerstyle2011.com/moncler-jackets-kids-c-7.htm final year of his http://www.monclerfactoryoutlets.com/ rookie contract, Forte has been one of the Bears' most http://www.idoudounemoncler.com/veste-moncler-femme-c-9.htm valuable players. He has also been http://www.idoudounemoncler.com/veste-moncler-homme-c-10.html durable during his career, starting all 60 games since he entered the league in 2008, but that run could
    http://www.idoudounemoncler.com/ be in jeopardy.

Write a comment