Javascript jQuery 24์๊ฐ ์๊ฐ๋น๊ต ์๊ฐ์ฐจ์ด ๊ตฌํํ๊ธฐ
์๋์ผ๋ก ์์์๊ฐ๊ณผ ์ข ๋ฃ์๊ฐ์ ์๊ฐ์ฐจ์ด๋ฅผ ๋ฃ์ด๋ฌ๋ผ๋ ์์ฒญ์ด์์ด์.....์ฒ๋ฆฌํ๊ฒ๋์์ด์.
ms-sql ์ฟผ๋ฆฌ๋ก๋ ์๊ฐ๋ง์ผ๋ก ์๊ฐ์ฐจ์ด๋ฅผ ๊ตฌํ ์ ์์๋๋ฐ;;;
javascript ์์๋ 0:00 ~13:00 ์ด๋ฐ์์ ์๊ฐ๋ง์ผ๋ก๋์๊ฐ์ฐจ์ด๋ฅผ ๊ตฌํ ์ ๊ฐ ์์์ด์.
๊ทธ๋์ ์ค์ ์กด์ฌํ๋ ์์์ ๊ธฐ์ค์ผ์ ์ค์ ํ๊ณ , FROM์ด TO ๋ณด๋ค ํฐ๊ฒฝ์ฐ์๋ ๋ค์๋ ๋ก ์ค์ ํ์์ต๋๋ค!!
์ด๋ถ๋ถ์ด ํต์ฌ!! ์ง์ง ๊ณ ๋ฏผ๊ณ ๋ฏผํ์์!
23:30(FROM)> 1:30(TO) ์ด๋ฐ๊ฒฝ์ฐ์ ๋ค์๋ ๋ก ์ค์ .
๊ทธ๋ฆฌ๊ณ ๊ธฐ์ค์ผ์ ๋ ์ง ํํ๋ 2020/10/20 "/"๋ก ๊ตฌ๋ถํด์ผ ie/chrome ๋๋ค ์๋์ด ๋ฉ๋๋ค!!
์์ฑํ ์ฝ๋์ ํธ์ถ ๋ฐฉ๋ฒ ์์๋ ์๋์ ๊ฐ์ต๋๋ค.
//alert(GetTimeDiff("2300", "400")); //5์๊ฐ ๋ฐํ
//alert(GetTimeDiff("2300", "400", "mm")); //300๋ถ ๋ฐํ
์๋๋ ๊ตฌํํ ์ํ์ ๋๋ค.
์๊ฐ
//์๋ฃํ์ ์๊ด์์ด ๊ฐ์ ์กด์ฌ ์ ๋ฌด ํ์ธ, true:์์, false:์์ ([], {} ๋ ๋น๊ฐ)
function isExist(val) {
if (val == "" || val == null || val == undefined || val == "undefined" || (val != null && typeof val == "object" && !Object.keys(val).length)) {
return false;
} else {
return true;
}
}
function SetTimeToString(intTime) {
var tmpString = "0:00";
var tmpInt = 0;
if (!isNaN(intTime)) {
tmpString = String(intTime); //๋ฌธ์ํ ๋ณํ
tmpInt = parseInt(intTime); //์ธํธํ
//์๊ฐํํ๋ก ๋ณํ
if (tmpInt <= 0 || tmpInt > 2400) { tmpString = "00:00:00"; } //์์ธ์ฒ๋ฆฌ ์ต๋ 24์๊ฐ, ๋ง์ด๋์ค์๊ฐ ์์
else if (tmpInt == 30) { tmpString = "00:30:00"; }
else if (tmpInt >= 100 && tmpInt < 1000) { tmpString = tmpString.substr(0, 1) + ":" + tmpString.substr(1, 2) + ":00"; }
else if (tmpInt >= 1000) { tmpString = tmpString.substr(0, 2) + ":" + tmpString.substr(2, 2) + ":00"; }
}
return tmpString;
}
function GetTimeDiff(sTime, eTime, tType) {
var tmpTime = "0";
var strStartTime = ""; //๋ฌธ์ํ
var strEndTime = ""; //๋ฌธ์ํ
if (!isNaN(sTime) && !isNaN(eTime)) {
//isNaN ์ซ์์ธ๊ฒฝ์ฐ false ๋ฐํ, ๊ทธ์ธ true
if (parseInt(sTime) == parseInt(eTime)) {
tmpTime = "24"; //์ต๋์๊ฐ 24์๊ฐ
} else {
strStartTime = SetTimeToString(sTime); //strStartTime์ ์๊ฐ ํํ์ ๋ฌธ์ํ์ผ๋ก ๋ณํ
strEndTime = SetTimeToString(eTime); //strEndTime์ ์๊ฐ ํํ์ ๋ฌธ์ํ์ผ๋ก ๋ณํ
//๊ธฐ์ค ๋ ์ง(2020/10/20)๋ ํจ์ ๋ง๋ ๋ ์ง๋ก ์์ ์ค์
strStartTime = "2020/10/20 " + strStartTime;
if (parseInt(sTime) > parseInt(eTime)) {
//strEndTime ์ ๋ค์๋ ๋ก ์ค์
strEndTime = "2020/10/21 " + strEndTime;
} else {
//strStartTime, strEndTime ๋์ผ๋ก ์ค์
strEndTime = "2020/10/20 " + strEndTime;
}
var sDate = new Date(strStartTime);
var eDate = new Date(strEndTime);
tmpTime = (eDate.getTime() - sDate.getTime()) / (1000 * 60 * (tType == "mm" ? 1 : 60)); //mm์ด๋ฉด ๋ถ๋จ์ ๋ฐํ, ๊ทธ์ธ ์๊ฐ ๋จ์ ๋ฐํ
}
}
return tmpTime;
}
function SetRealWorkTime() {
var workTimeFrom = $("#sltWorkTimeFrom option:selected").val(); //์์์๊ฐ
var workTimeTo = $("#sltWorkTimeTo option:selected").val(); //์ข
๋ฃ์๊ฐ
if (isExist(workTimeFrom) && isExist(workTimeTo)) {
$("#txtReal_WorkTime").val(GetTimeDiff(workTimeFrom, workTimeTo));
} else {
$("#txtReal_WorkTime").val("0");
}
//alert(GetTimeDiff("2300", "400")); //5์๊ฐ ๋ฐํ
//alert(GetTimeDiff("2300", "400", "mm")); //300๋ถ ๋ฐํ
}
'์ ํธํ๋๊ฐ๋ฐ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
ํฌ๋กฌ๋ธ๋ผ์ฐ์ ๋ฐ๋ก๊ฐ๊ธฐ ์ค์ ์์ https ์ธ์ฆ์ ์ค๋ฅ ๋ฌด์์ค์ (0) | 2021.01.18 |
---|---|
c# .Net int.TryParse ์ค๋ฅ๊น์ง ํ๋ฒ์ ์์ธ์ฒ๋ฆฌ (1) | 2021.01.07 |
๋ค์ด๋ฒ ์จ์ผ๋ธ๋ผ์ฐ์ ํ์ฅ์ฑ ๊ฐ๋ฐ์์?! (0) | 2020.09.09 |
webcopy cyowcopy!! ์น์ฌ์ดํธ๋ฅผ ๋ณต์ ํ๋ ํ๋ก๊ทธ๋จ ๋ฉ๋ชจ (0) | 2020.05.29 |
javascript ๊ถํ ๊ด๋ จํ์ฌ ๊ฐ ์ฒ๋ฆฌํ๊ธฐ (0) | 2020.04.22 |