java 자바 Random Calendar Math 클래스
/**
* 오늘날짜(년/월/일/요일)을 구해서 String형으로 바꾸는 부분
* --> 필요한 이유는 밑에밑에 소스를 보면 알수 있다. ㅋ
* 날짜(date)를 받을 int형 변수선언{ yaar 년 / month 월 / date 일 / day 요일 }
* 날짜(date)를 받을 String형 변수선언{ sYaar 년 / sMonth 월 / sDate 일 / sDay 요일 }
* Calendat객체 생성
* get메소드는 리턴형이 int형이어서 다음과 같이 int형으로 받고 그걸 다시 문자형으로 바꿔준다.
* Calendar.MONTH를 할때에 1월이면 0, 2월이면 1을 리턴하기 때문에 month부분에 +1 을 해준다.
*/
// int 변수선언
int year,month,date,day;
// String 변수선언
String sYear,sMonth,sDate,sDay;
//Calendar 객체생성
Calendar todayDate = Calendar.getInstance();< /FONT >
//년,월,일,요일 받기(int형)
year = todayDate.get(Calendar.YEAR);
month = todayDate.get(Calendar.MONTH)+1;
date = todayDate.get(Calendar.DATE);
day = todayDate.get(Calendar.DAY_OF_WEEK);
//년,월,일,요일을 String형으로..
sYear = String.valueOf(year);
sMonth = String.valueOf(month);
sDate = String.valueOf(date);
sDay = String.valueOf(day);
*/
Tip)
자리수 맞추기
if(days.length==1) days = "0"+days; //01로 표현
if(month.length==1) month = "0"+month;//01로 표현
다른 날짜구하는 포멧
Date date = new Date();
SimpleDateFormat simpleDate = new SimpleDateFormat("yyyy-MM-dd (a) hh:mm:ss (E)");
String strdate = simpleDate.format(date);< /FONT >
DateFormat format = new SimpleDateFormat("EE");< /FONT >
c.set(Calendar.WEEK_OF_YEAR, 45);
System.out.println("Month: " + (c.get(Calendar.MONTH)+1));
for(int i = 1; i <= 7; ++i) {
c.set(Calendar.DAY_OF_WEEK, i);
System.out.println(c.get(Calendar.DATE) + " " + format.format(c.getTime()));
}