javascript 자바스크립트 날짜에 해당 월 주차 구하기(달력)
페이지 정보
본문
<!doctype html>
<html lang=\"ko\">
<head>
<meta charset=\"euc-kr\">
<title>자바스크립트 특정일에 동작</title>
</head>
<body>
안녕하세요.. ^^
<script type=\"text/javascript\">
//alert('test');
var date_w = new Date();
document.write(\"이것은 자바스크립트 입니다.<br>\");
document.write(date_w+\"<br>\");
document.write(date_w.getFullYear()+\"<br>\");
document.write(date_w.getMonth()+1+\"<br>\");
document.write(date_w.getDate()+\"<br>\");
document.write(date_w.getDay()+\"<br>\");
document.write(date_w.getHours()+\"<br>\");
var view_date = String(date_w.getFullYear()) + String(date_w.getMonth()+1) + String(date_w.getDate()) + String(date_w.getHours());
document.write(view_date+\"<br>\");
/*
// This script is released to the public domain and may be used, modified and
// distributed without restrictions. Attribution not necessary but appreciated.
// Source: http://weeknumber.net/how-to/javascript
// Returns the ISO week of the date.
Date.prototype.getWeek = function() {
var date = new Date(this.getTime());
date.setHours(0, 0, 0, 0);
// Thursday in current week decides the year.
date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7);
// January 4 is always in week 1.
var week1 = new Date(date.getFullYear(), 0, 4);
// Adjust to Thursday in week 1 and count number of weeks from date to week1.
return 1 + Math.round(((date.getTime() - week1.getTime()) / 86400000 - 3 + (week1.getDay() + 6) % 7) / 7);
}
// Returns the four-digit year corresponding to the ISO week of the date.
Date.prototype.getWeekYear = function() {
var date = new Date(this.getTime());
date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7);
return date.getFullYear();
}
var mydate = new Date();
//var mydate = \"Mon Feb 2 10:45:52 UTC+0900 2015\";
alert(mydate);
alert(mydate.getWeek());
alert(mydate.getWeekYear());
*/
/*
//월요일을 중심으로한 주차 구하기
//차일 변수
var minusDay = 0;
//주차를 계산하고픈 일
//var wkDtStr = \"20130901\";
var wkDtStr = \"20150109\";
//계산하고픈달 시작일 1일
var stDtStr = wkDtStr.substring(0,6) + \"01\";
var stDtCal = new Date( stDtStr.substring(0,4) , stDtStr.substring(4,6) , stDtStr.substring(6,8) );
//요일 구하기
var weekCal = new Date( wkDtStr.substring(0,4) , ( wkDtStr.substring(4,6) - 1 ) , wkDtStr.substring(6,8) );
//주차를 계산하고픈 일 달력 생성
var wkDtCal = new Date( wkDtStr.substring(0,4) , wkDtStr.substring(4,6) , wkDtStr.substring(6,8) );
//매달 시작일에 따른 빼줘야 하는 값
var week = new Array( 1, 0, 5, 4, 3, 2, 1 );
minusDay = wkDtCal.getDate() - stDtCal.getDate() - week[ weekCal.getDay() ] ;
//만약 2일부터 1주차인데 1일을 입력했을경우 혹은 년도가 바뀔경우
if( ( minusDay - week[ weekCal.getDay() ] ) < 0 ){
wkDtCal.setDate( stDtCal.getDate() - 1 );
stDtCal.setDate( stDtCal.getDate() - wkDtCal.getDate() );
minusDay = wkDtCal.getDate() - stDtCal.getDate();
// alert( \"변경된 시작일 : \" + stDtCal.getYear() + stDtCal.getMonth() + stDtCal.getDate() + \"\" );
// alert( \"변경된 마지막일 : \" + wkDtCal.getYear() + wkDtCal.getMonth() + wkDtCal.getDate() + \"\" );
// alert( \"두 날짜 차일 : \" + wkDtCal.getDate() - stDtCal.getDate() );
}
var weekNm = minusDay / 7 + 1;
//연산
alert( wkDtCal.getYear() + \"년\" + wkDtCal.getMonth() + \"월\" + parseInt(weekNm) + \" 주차 \" );
*/
/*
Date.prototype.getWeek = function() {
var onejan = new Date(this.getFullYear(),0,1);
alert(onejan.getDay());
return Math.ceil((((this - onejan) / 86400000) + onejan.getDay()+1)/7);
}
var today = new Date();
var weekno = today.getWeek();
if(today.getMonth() == 0){
alert(weekno);
}else if(today.getMonth() == 1){
alert(weekno-5);
}else if(today.getMonth() == 2){
alert(weekno-9);
}else if(today.getMonth() == 3){
alert(weekno-14);
}
*/
function weekAndDay() {
//var date = new Date,
var date = new Date(2015,1,7),
days = ['Sunday','Monday','Tuesday','Wednesday',
'Thursday','Friday','Saturday'],
prefixes = ['First', 'Second', 'Third', 'Fourth', 'Fifth'];
return prefixes[0 | date.getDate() / 7] + ' ' + days[date.getDay()];
}
var week_date = weekAndDay(); // => \"Third Monday\"
alert(week_date);
function getWeekCountOfMonth(dateStr) {
var year = Number(dateStr.substring(0, 4));
var month = Number(dateStr.substring(4, 6));
var nowDate = new Date(year, month-1, 1);
var lastDate = new Date(year, month, 0).getDate();
var monthSWeek = nowDate.getDay();
var weekSeq = parseInt((parseInt(lastDate) + monthSWeek - 1)/7) + 1;
return weekSeq;
}
//alert(getWeekCountOfMonth('201503'));
var date = '201502021';
function getSecofWeek(date){
var d = new Date( date.substring(0,4), parseInt(date.substring(4,6))-1, date.substring(6,8) );
var fd = new Date( date.substring(0,4), parseInt(date.substring(4,6))-1, 1 );
return Math.ceil((parseInt(date.substring(6,8))+fd.getDay())/7);
}
alert(getSecofWeek('20150228'));
</script>
<%
Response.write \"주단위:\" & weekday(date) & \"<br>\"
Response.write \"주단위:\" & weekday(2015-01-15) & \"<br>\"
Response.write \"date:\" & Date() & \"<br>\"
Response.write \"now:\" & now() & \"<br>\"
%>
</body>
</html>
<html lang=\"ko\">
<head>
<meta charset=\"euc-kr\">
<title>자바스크립트 특정일에 동작</title>
</head>
<body>
안녕하세요.. ^^
<script type=\"text/javascript\">
//alert('test');
var date_w = new Date();
document.write(\"이것은 자바스크립트 입니다.<br>\");
document.write(date_w+\"<br>\");
document.write(date_w.getFullYear()+\"<br>\");
document.write(date_w.getMonth()+1+\"<br>\");
document.write(date_w.getDate()+\"<br>\");
document.write(date_w.getDay()+\"<br>\");
document.write(date_w.getHours()+\"<br>\");
var view_date = String(date_w.getFullYear()) + String(date_w.getMonth()+1) + String(date_w.getDate()) + String(date_w.getHours());
document.write(view_date+\"<br>\");
/*
// This script is released to the public domain and may be used, modified and
// distributed without restrictions. Attribution not necessary but appreciated.
// Source: http://weeknumber.net/how-to/javascript
// Returns the ISO week of the date.
Date.prototype.getWeek = function() {
var date = new Date(this.getTime());
date.setHours(0, 0, 0, 0);
// Thursday in current week decides the year.
date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7);
// January 4 is always in week 1.
var week1 = new Date(date.getFullYear(), 0, 4);
// Adjust to Thursday in week 1 and count number of weeks from date to week1.
return 1 + Math.round(((date.getTime() - week1.getTime()) / 86400000 - 3 + (week1.getDay() + 6) % 7) / 7);
}
// Returns the four-digit year corresponding to the ISO week of the date.
Date.prototype.getWeekYear = function() {
var date = new Date(this.getTime());
date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7);
return date.getFullYear();
}
var mydate = new Date();
//var mydate = \"Mon Feb 2 10:45:52 UTC+0900 2015\";
alert(mydate);
alert(mydate.getWeek());
alert(mydate.getWeekYear());
*/
/*
//월요일을 중심으로한 주차 구하기
//차일 변수
var minusDay = 0;
//주차를 계산하고픈 일
//var wkDtStr = \"20130901\";
var wkDtStr = \"20150109\";
//계산하고픈달 시작일 1일
var stDtStr = wkDtStr.substring(0,6) + \"01\";
var stDtCal = new Date( stDtStr.substring(0,4) , stDtStr.substring(4,6) , stDtStr.substring(6,8) );
//요일 구하기
var weekCal = new Date( wkDtStr.substring(0,4) , ( wkDtStr.substring(4,6) - 1 ) , wkDtStr.substring(6,8) );
//주차를 계산하고픈 일 달력 생성
var wkDtCal = new Date( wkDtStr.substring(0,4) , wkDtStr.substring(4,6) , wkDtStr.substring(6,8) );
//매달 시작일에 따른 빼줘야 하는 값
var week = new Array( 1, 0, 5, 4, 3, 2, 1 );
minusDay = wkDtCal.getDate() - stDtCal.getDate() - week[ weekCal.getDay() ] ;
//만약 2일부터 1주차인데 1일을 입력했을경우 혹은 년도가 바뀔경우
if( ( minusDay - week[ weekCal.getDay() ] ) < 0 ){
wkDtCal.setDate( stDtCal.getDate() - 1 );
stDtCal.setDate( stDtCal.getDate() - wkDtCal.getDate() );
minusDay = wkDtCal.getDate() - stDtCal.getDate();
// alert( \"변경된 시작일 : \" + stDtCal.getYear() + stDtCal.getMonth() + stDtCal.getDate() + \"\" );
// alert( \"변경된 마지막일 : \" + wkDtCal.getYear() + wkDtCal.getMonth() + wkDtCal.getDate() + \"\" );
// alert( \"두 날짜 차일 : \" + wkDtCal.getDate() - stDtCal.getDate() );
}
var weekNm = minusDay / 7 + 1;
//연산
alert( wkDtCal.getYear() + \"년\" + wkDtCal.getMonth() + \"월\" + parseInt(weekNm) + \" 주차 \" );
*/
/*
Date.prototype.getWeek = function() {
var onejan = new Date(this.getFullYear(),0,1);
alert(onejan.getDay());
return Math.ceil((((this - onejan) / 86400000) + onejan.getDay()+1)/7);
}
var today = new Date();
var weekno = today.getWeek();
if(today.getMonth() == 0){
alert(weekno);
}else if(today.getMonth() == 1){
alert(weekno-5);
}else if(today.getMonth() == 2){
alert(weekno-9);
}else if(today.getMonth() == 3){
alert(weekno-14);
}
*/
function weekAndDay() {
//var date = new Date,
var date = new Date(2015,1,7),
days = ['Sunday','Monday','Tuesday','Wednesday',
'Thursday','Friday','Saturday'],
prefixes = ['First', 'Second', 'Third', 'Fourth', 'Fifth'];
return prefixes[0 | date.getDate() / 7] + ' ' + days[date.getDay()];
}
var week_date = weekAndDay(); // => \"Third Monday\"
alert(week_date);
function getWeekCountOfMonth(dateStr) {
var year = Number(dateStr.substring(0, 4));
var month = Number(dateStr.substring(4, 6));
var nowDate = new Date(year, month-1, 1);
var lastDate = new Date(year, month, 0).getDate();
var monthSWeek = nowDate.getDay();
var weekSeq = parseInt((parseInt(lastDate) + monthSWeek - 1)/7) + 1;
return weekSeq;
}
//alert(getWeekCountOfMonth('201503'));
var date = '201502021';
function getSecofWeek(date){
var d = new Date( date.substring(0,4), parseInt(date.substring(4,6))-1, date.substring(6,8) );
var fd = new Date( date.substring(0,4), parseInt(date.substring(4,6))-1, 1 );
return Math.ceil((parseInt(date.substring(6,8))+fd.getDay())/7);
}
alert(getSecofWeek('20150228'));
</script>
<%
Response.write \"주단위:\" & weekday(date) & \"<br>\"
Response.write \"주단위:\" & weekday(2015-01-15) & \"<br>\"
Response.write \"date:\" & Date() & \"<br>\"
Response.write \"now:\" & now() & \"<br>\"
%>
</body>
</html>
관련링크
-
https://ddakker.tistory.com/259
5891회 연결
- 이전글javascript 브라우저 x버튼 클릭시 동작.(브라두져 닫기 동작) 20.02.21
- 다음글javascript 배너 이미지 랜덤 표시 20.02.21
댓글목록
등록된 댓글이 없습니다.