<div class="codetitle"> <span><a style="CURSOR: pointer" data="69366" class="copybut" id="copybut69366" onclick="doCopy('code69366')"><u>复代码</u></a></span> 代码如下:</div> <div class="codebody" id="code69366"> <br><script type="text/javascript"> <br>function NewDate(str) { <br>str = str.split('-'); <br>var date = new Date(); <br>date.setUTCFullYear(str[0], str[1] - 1, str[2]); <br>date.setUTCHours(0, 0, 0, 0); <br>귀국 날짜; <br>} <br>function TimeCom(dateValue) { <br>var newCom; <br><br>if (dateValue == "") { <br>newCom = new Date(); <br>} else { <br>newCom = NewDate(dateValue); <br>} <br>this.year = newCom.getYear(); <br>this.month = newCom.getMonth() 1; <br>this.day = newCom.getDate(); <br>this.hour = newCom.getHours(); <br>this.분 = newCom.getMinutes(); <br>this.second = newCom.getSeconds(); <br>this.msecond = newCom.getMilliseconds(); <br>this.week = newCom.getDay(); <br>} <br>function DateDiff(간격, 날짜1, 날짜2) { <br>var TimeCom1 = new TimeCom(date1); <br>var TimeCom2 = new TimeCom(date2); <br>var 결과; <br>switch (String(interval).toLowerCase()) { <br>case "y": <br>case "year": <br>result = TimeCom1.year - TimeCom2.year; <br>휴식; <br>케이스 "m": <br>케이스 "월": <br>result = (TimeCom1.year - TimeCom2.year) * 12 (TimeCom1.month - TimeCom2.month); <br>휴식; <br>케이스 "d": <br>케이스 "일": <br>result = Math.round((Date.UTC(TimeCom1.year, TimeCom1.month - 1, TimeCom1.day) - Date.UTC(TimeCom2 .년, TimeCom2.월 - 1, TimeCom2.day)) / (1000 * 60 * 60 * 24)); <br>휴식; <br>케이스 "h": <br>케이스 "시간": <br>result = Math.round((Date.UTC(TimeCom1.year, TimeCom1.month - 1, TimeCom1.day, TimeCom1.hour) - 날짜 .UTC(TimeCom2.year, TimeCom2.month - 1, TimeCom2.day, TimeCom2.hour)) / (1000 * 60 * 60)); <br>휴식; <br>케이스 "분": <br>케이스 "분": <br>result = Math.round((Date.UTC(TimeCom1.year, TimeCom1.month - 1, TimeCom1.day, TimeCom1.hour, TimeCom1. 분) - Date.UTC(TimeCom2.년, TimeCom2.월 - 1, TimeCom2.day, TimeCom2.hour, TimeCom2.분)) / (1000 * 60)); <br>휴식; <br>케이스 "s": <br>케이스 "두 번째": <br>result = Math.round((Date.UTC(TimeCom1.year, TimeCom1.month - 1, TimeCom1.day, TimeCom1.hour, TimeCom1. 분, TimeCom1.초) - Date.UTC(TimeCom2.year, TimeCom2.month - 1, TimeCom2.day, TimeCom2.hour, TimeCom2.분, TimeCom2.second)) / 1000); <br>휴식; <br>case "ms": <br>case "msecond": <br>result = Date.UTC(TimeCom1.year, TimeCom1.month - 1, TimeCom1.day, TimeCom1.hour, TimeCom1. Minute, TimeCom1.second , TimeCom1.m초) - Date.UTC(TimeCom2.year, TimeCom2.month - 1, TimeCom2.day, TimeCom2.hour, TimeCom2.min, TimeCom2.second, TimeCom1.msecond); <br>휴식; <br>케이스 "w": <br>케이스 "주": <br>result = Math.round((Date.UTC(TimeCom1.year, TimeCom1.month - 1, TimeCom1.day) - Date.UTC(TimeCom2 .년, TimeCom2.월 - 1, TimeCom2.day)) / (1000 * 60 * 60 * 24)) % 7; <br>휴식; <br>기본값: <br>결과 = "잘못됨"; <br>} <br>반환(결과); <br>} <br></script> <br> </div>