[javascript] 자바스크립트 달력 요일 가져오기
// 특정 연월의 첫날(1일) 날짜 객체 가져오기
function getFirstDateObjFromMonth(_year, _month) {
_year = parseInt(_year, 10);
_month = parseInt(_month, 10);
_month = _month – 1;
var firstDateObj = new Date(_year, _month, 1);
return firstDateObj;
}
// 특정 연월의 마지막날 날짜 객체 가져오기
function getLastDateObjFromMonth(_year, _month) {
_year = parseInt(_year, 10);
_month = parseInt(_month, 10);
_month = _month;
var lastDateObj = new Date(_year, _month, 0);
return lastDateObj;
}
// 날짜텍스트 가져오기 (ex : 20200101)
function getDateText(_dateObj) {
if (_dateObj == null) {
_dateObj = new Date();
}
var dd = _dateObj.getDate();
var mm = _dateObj.getMonth() + 1; // January is 0!
var yyyy = _dateObj.getFullYear();
if (dd < 10) {
dd = “0” + dd;
}
if (mm < 10) {
mm = “0” + mm;
}
return (yyyy + “” + mm + “” + dd);
}
// 요일텍스트 가져오기. 문자열 리턴. SUN ~ SAT
function getYoilText(_dateObj) {
if (_dateObj == null) {
_dateObj = new Date();
}
var yoilValue = _dateObj.getDay();
var week = new Array(“SUN”, “MON”, “TUE”, “WED”, “THU”, “FRI”, “SAT”);
var yoilText = week[yoilValue];
return yoilText;
}
// 요일값 가져오기. 숫자 리턴. 0(SUN)~ 7(SAT)
function getYoilValue(_dateObj) {
if (_dateObj == null) {
_dateObj = new Date();
}
var yoilValue = _dateObj.getDay();
return yoilValue;
}