일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- open redirect
- 거래사기
- 모의해킹
- Malware Sample
- 네이버카페
- MongoDB #NoSQL #CreateUser #DropUser #mongod #mognod.conf
- 중고나라
- 보이스피싱 #대검찰청 #명의도용 #비밀번호 #계좌번호 #공공기관 #가짜검찰청
- NUGU
- 많다..
- 허리디스크
- ssrf
- speed-measure-webpack-plugin
- 변태는
- react
- 로맨스스캠
- ue4dumper
- intelmac
- self-signed
- 척추관협착증
- CJ대한통운 #쿠팡 #통관번호오류 #통관고유번호오류 #안주원팀장 #모건인베스트
- XSS
- 채팅환전사기
- shell_gpt
- CryptoJS
- 취약점
- 안전결제
- esbuild
- Sequoia
- Frida
Archives
- Today
- Total
annyoung
[javascript] calculate datetime 본문
Calculate datetime 2 ways.
1 way will be calculate about YYYY-MM - YYYY-MM
function calMonthRange(val1, val2)
{
var FORMAT = "-";
if (val1.length != 7 || val2.length != 7)
return null;
if (val1.indexOf(FORMAT) < 0 || val2.indexOf(FORMAT) < 0)
return null;
var start_dt = val1.split(FORMAT);
var end_dt = val2.split(FORMAT);
start_dt[1] = (Number(start_dt[1]) - 1) + "";
end_dt[1] = (Number(end_dt[1]) - 1) + "";
var from_dt = new Date(start_dt[0], start_dt[1]);
var to_dt = new Date(end_dt[0], end_dt[1]);
return Math.ceil((to_dt.getTime() - from_dt.getTime()) / 1000 / 60 / 60 / 24 / 30);
}
calMonthRange("2017-08", "2018-04")
/*
Debugging output
*/
9
/*
1 way apply code
*/
function formatMonth(date) {
var d = new Date(date),
month = '' + (d.getMonth() + 1),
year = d.getFullYear();
if (month.length < 2) month = '0' + month;
return [year, month].join('-');
}
function calMonthRange(val1, val2)
{
var FORMAT = "-";
if (val1.length != 7 || val2.length != 7)
return null;
if (val1.indexOf(FORMAT) < 0 || val2.indexOf(FORMAT) < 0)
return null;
var start_dt = val1.split(FORMAT);
var end_dt = val2.split(FORMAT);
start_dt[1] = (Number(start_dt[1]) - 1) + "";
end_dt[1] = (Number(end_dt[1]) - 1) + "";
var from_dt = new Date(start_dt[0], start_dt[1]);
var to_dt = new Date(end_dt[0], end_dt[1]);
return Math.ceil((to_dt.getTime() - from_dt.getTime()) / 1000 / 60 / 60 / 24 / 30);
}
for(var i=0; i<calMonthRange("2017-08", "2018-04"); i++) {
console.log(formatMonth(new Date("2017-08").setMonth(new Date("2017-08").getMonth() + i)))
}
/*
Debugging output
*/
2017-08
2017-09
2017-10
2017-11
2017-12
2018-01
2018-02
2018-03
2018-04
2 way will be calculate about YYYY-MM-DD - YYYY-MM-DD
function calDateRange(val1, val2)
{
var FORMAT = "-";
if (val1.length != 10 || val2.length != 10)
return null;
if (val1.indexOf(FORMAT) < 0 || val2.indexOf(FORMAT) < 0)
return null;
var start_dt = val1.split(FORMAT);
var end_dt = val2.split(FORMAT);
start_dt[1] = (Number(start_dt[1]) - 1) + "";
end_dt[1] = (Number(end_dt[1]) - 1) + "";
var from_dt = new Date(start_dt[0], start_dt[1], start_dt[2]);
var to_dt = new Date(end_dt[0], end_dt[1], end_dt[2]);
return (to_dt.getTime() - from_dt.getTime()) / 1000 / 60 / 60 / 24;
}
calDateRange("2018-03-22", "2018-04-24")
/*
Debugging output
*/
33
/*
2 way apply code
*/
function formatDate(date) {
var d = new Date(date),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2) month = '0' + month;
if (day.length < 2) day = '0' + day;
return [year, month, day].join('-');
}
function calDateRange(val1, val2)
{
var FORMAT = "-";
if (val1.length != 10 || val2.length != 10)
return null;
if (val1.indexOf(FORMAT) < 0 || val2.indexOf(FORMAT) < 0)
return null;
var start_dt = val1.split(FORMAT);
var end_dt = val2.split(FORMAT);
start_dt[1] = (Number(start_dt[1]) - 1) + "";
end_dt[1] = (Number(end_dt[1]) - 1) + "";
var from_dt = new Date(start_dt[0], start_dt[1], start_dt[2]);
var to_dt = new Date(end_dt[0], end_dt[1], end_dt[2]);
return (to_dt.getTime() - from_dt.getTime()) / 1000 / 60 / 60 / 24;
}
for(var i=0; i<calDateRange("2018-03-22", "2018-04-24"); i++) {
console.log(formatDate(new Date("2018-03-22").setDate(new Date("2018-03-22").getDate() + i)))
}
/*
Debugging output
*/
2018-03-22
2018-03-23
2018-03-24
2018-03-25
2018-03-26
2018-03-27
2018-03-28
2018-03-29
2018-03-30
2018-03-31
2018-04-01
2018-04-02
2018-04-03
2018-04-04
2018-04-05
2018-04-06
2018-04-07
2018-04-08
2018-04-09
2018-04-10
2018-04-11
2018-04-12
2018-04-13
2018-04-14
2018-04-15
2018-04-16
2018-04-17
2018-04-18
2018-04-19
2018-04-20
2018-04-21
2018-04-22
2018-04-23
'프로그래밍' 카테고리의 다른 글
python get image from video using cv2 (VIDEOIO ERROR: V4L: can't find camera device) (0) | 2019.01.30 |
---|---|
python pyodbc 설치 탐험기 (0) | 2018.06.04 |
[javascript] get ip only using javascript (5) | 2018.04.19 |
python ctypes GetFileVersion (0) | 2016.11.09 |
python 윈도우 한글문제 (0) | 2016.04.26 |
Comments