2013. 3. 11. 10:36ㆍ99. 정리전 - IT/12. Javascript
java
public String getWeekDay(String day) {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, Integer.parseInt(day.substring(0,4)));
cal.set(Calendar.MONTH, Integer.parseInt(day.substring(4,6)) -1);
cal.set(Calendar.DATE, Integer.parseInt(day.substring(6,8)));
String[] dayOfWeek = {"일","월","화","수","목","금","토"};
String weekday = dayOfWeek[cal.get(Calendar.DAY_OF_WEEK)-1];
return weekday ;
}
javascript
// 요일구하기 함수
function ext_day(n_year,n_month,n_day){
var p_year = n_year -1;
var p_month = n_month-1;
var ext = 0;
ext = parseInt((p_year*365 + parseInt(p_year/4) + day_cnt(n_year,p_month) + e_day -1)%7)
return day_str(ext)
}
//날짜 수 계산(요일 구하기 함수의 부분....)
function day_cnt(year, month) {
if(month==1) return 31
else if(month==2){
if(year%4==0) return 60
else return 59
}
else if(month==3){
if(year%4==0) return 91
else return 90
}
else if(month==4){
if(year%4==0) return 121
else return 120
}
else if(month==5){
if(year%4==0) return 152
else return 151
}
else if(month==6){
if(year%4==0) return 182
else return 181
}
else if(month==7){
if(year%4==0) return 213
else
return 212
}
else if(month==8){
if(year%4==0) return 244
else return 243
}
else if(month==9){
if(year%4==0) return 274
else return 273
}
else if(month==10){
if(year%4==0) return 305
else return 304
}
else if(month==11){
if(year%4==0) return 335
else return 334
}
else if(month==12){
if(year%4==0) return 366
else return 365
}
}
// 요일 표시(요일 구하기 함수의 부분....)
function day_str(num) {
if(num==0) return "일"
else if(num==1) return "월"
else if(num==2) return "화"
else if(num==3) return "수"
else if(num==4) return "목"
else if(num==5) return "금"
else return "토"
-------------------------------------------
사용예
ext_day(2013, 3, 11);