2012. 1. 3. 10:04 PROGRAMMING
[JAVA] 자바 달력 날짜 사용법, 현재날짜, 현재시간, 24시 java.util.Calendar
년, 월, 일, 시, 분, 초, 24시, 밀리초, 요일 구하기

소스 
import java.util.Calendar;

public class Calendar{
	public static void main(String args[]){
		Calendar calendar=Calendar.getInstance( );
		System.out.println("YEAR "+calendar.get(Calendar.YEAR));
		System.out.println("MONTH "+calendar.get(Calendar.MONTH)+1);
		System.out.println("DAY OF MONTH "+calendar.get(Calendar.DAY_OF_MONTH));
		System.out.println("HOUR OF DAY "+calendar.get(Calendar.HOUR_OF_DAY)); // 24시간
		System.out.println("MINUTE "+calendar.get(Calendar.MINUTE));
		System.out.println("SECOND "+calendar.get(Calendar.SECOND));
		System.out.print("HOUR AM/PM "+calendar.get(Calendar.HOUR));
		if (calendar.get(Calendar.AM_PM)==0) System.out.println("AM");
		else System.out.println("PM");

		System.out.println("MILLISECOND "+calendar.get(Calendar.MILLISECOND));
		System.out.println("DAY OF WEEK "+calendar.get(Calendar.DAY_OF_WEEK)); // 일요일= 1
		System.out.println("DAY OF YEAR "+calendar.get(Calendar.DAY_OF_YEAR)); // 1월1일=1
		System.out.println("WEEK OF YEAR "+calendar.get(Calendar.WEEK_OF_YEAR)); // 1월1일=1
		System.out.println("WEEK OF MONTH "+calendar.get(Calendar.WEEK_OF_MONTH)); // 첫째주=1
	}
}


결과
YEAR 2012
MONTH 01
DAY OF MONTH 3
HOUR OF DAY 10
MINUTE 0
SECOND 31
HOUR AM/PM 10AM
MILLISECOND 852
DAY OF WEEK 3
DAY OF YEAR 3
WEEK OF YEAR 1
WEEK OF MONTH 1

최근에 올라온 글

최근에 달린 댓글