1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | import java.util.Date; import java.util.Calendar; import java.util.Scanner; class DateTime { public static void main(String[] args) { //날짜 & 시간 //n:시간과 시각(특정한시점)은 자료형이 다르다, ex)2014.12.16시간 14h:15m:30s시각 //1. Date 클래스(구) //2. Calendar 클래스(신) -> 신버젼만 사용됨 //ex) 메소드 만들어 설명 //m1(); m2(); } public static void m1() { //Date 클래스 int n =10; Date d1 = new Date(); //**현재 시스템의 날짜 & 시간, 처음얻어온 시간이 저장돼있는 상태, 고정값 //(왼:변수) = (오:데이터) System.out.println(d1); Scanner scan = new Scanner(System.in); scan.nextLine(); System.out.println(d1); Date d2 = new Date(); //d2를 만들어 현재 시간의 데이터를 얻어온다 System.out.println(d2); } public static void m2() { //Calendar 클래스 //현재 시간 얻어오기 Calendar c1 = Calendar.getInstance(); //System.out.println(c1); ->c1의 덩어리 중에 뽑아와야.. //원하는 항목 가져오기 // int get(int n) int result = c1.get(1); System.out.println(result); result = c1.get(2); System.out.println(result); result = c1.get(3); System.out.println(result); //Calendar 상수제공 -> 변수 System.out.println(Calendar.YEAR); // result = c1.get(Calendar.YEAR); System.out.println(result); System.out.println(70); //이렇게만 써놓으면 70이 뭔지 모르잖아.. int weight = 70; //이렇게 System.out.println(weight); System.out.println(c1.get(Calendar.YEAR)); //년 System.out.println(c1.get(Calendar.MONTH)); //월(0~11) **0부터시작, 주의 System.out.println(c1.get(Calendar.DATE)); //일 System.out.println(c1.get(Calendar.HOUR)); //시(12) System.out.println(c1.get(Calendar.HOUR_OF_DAY)); //시(24) System.out.println(c1.get(Calendar.MINUTE)); //분 System.out.println(c1.get(Calendar.SECOND)); //초 System.out.println(c1.get(Calendar.MILLISECOND)); //밀리초 System.out.println(c1.get(Calendar.DAY_OF_WEEK)); //요일(일-1, 토-7) System.out.println(c1.get(Calendar.AM_PM)); //AM - 0, PM - 1 //오늘이 몇년 몇월 몇일입니까? System.out.printf("오늘은 %d년 %d월 %d일입니다.\n" , c1.get(Calendar.YEAR) , c1.get(Calendar.MONTH) + 1 //11월로 출력되므로 +1 해준다. , c1.get(Calendar.DATE)); } } | cs |
'WEB > JAVA' 카테고리의 다른 글
IF문 (0) | 2015.05.22 |
---|---|
날짜&시간2 (4) | 2015.05.22 |
메소드6 (예제) (0) | 2015.05.22 |
메소드5 (재귀 메소드) (0) | 2015.05.22 |
메소드4 (메소드 오버로딩) (0) | 2015.05.22 |