<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>関数 NewDate(str) { <br>str = str.split('-'); <br>var date = new Date(); <br>date.setUTCFull Year(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. minutes = newCom.getMinutes(); <br>this.second = newCom.getSeconds(); <br>this.msec = newCom.getMilliseconds(); <br>this.week = newCom.getDay(); <br>} <br>function DateDiff(interval, date1, date2) { <br>var TimeCom1 = new TimeCom(date1); <br>var TimeCom2 = 新しい 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>結果 = (TimeCom1.year - TimeCom2.year) * 12 (TimeCom1.month - TimeCom2.month); <br>休憩; <br>ケース "d": <br>ケース "日": <br>結果 = Math.round((Date.UTC(TimeCom1.year, TimeCom1.month - 1, TimeCom1.day) - Date.UTC(TimeCom2 .year, TimeCom2.month - 1, TimeCom2.day)) / (1000 * 60 * 60 * 24)); <br>休憩; <br>case "h": <br>case "hour": <br>result = Math.round((Date.UTC(TimeCom1.year, TimeCom1.month - 1, TimeCom1.day, TimeCom1.hour) - Date .UTC(TimeCom2.year, TimeCom2.month - 1, TimeCom2.day, TimeCom2.hour)) / (1000 * 60 * 60)); <br>休憩; <br>ケース "分": <br>ケース "分": <br>結果 = Math.round((Date.UTC(TimeCom1.year, TimeCom1.month - 1, TimeCom1.day, TimeCom1.hour, TimeCom1.分) - Date.UTC(TimeCom2.year, TimeCom2.month - 1, TimeCom2.day, TimeCom2.hour, TimeCom2.minut)) / (1000 * 60)); <br>休憩; <br>ケース "s": <br>ケース "秒": <br>結果 = Math.round((Date.UTC(TimeCom1.year, TimeCom1.month - 1, TimeCom1.day, TimeCom1.hour, TimeCom1.分, TimeCom1.秒) - Date.UTC(TimeCom2.年, TimeCom2.月 - 1, TimeCom2.日, TimeCom2.時間, TimeCom2.分, TimeCom2.秒)) / 1000); <br>休憩; <br>ケース "ms": <br>ケース "ミリ秒": <br>結果 = Date.UTC(TimeCom1.year, TimeCom1.month - 1, TimeCom1.day, TimeCom1.hour, TimeCom1.nutrition, TimeCom1.秒、TimeCom1.m秒) - Date.UTC(TimeCom2.年、TimeCom2.month - 1、TimeCom2.日、TimeCom2.時間、TimeCom2.分、TimeCom2.秒、TimeCom1.m秒); <br>休憩; <br>case "w": <br>case "week": <br>result = Math.round((Date.UTC(TimeCom1.year, TimeCom1.month - 1, TimeCom1.day) - Date.UTC(TimeCom2 .year, TimeCom2.month - 1, TimeCom2.day)) / (1000 * 60 * 60 * 24)) % 7; <br>休憩; <br>デフォルト: <br>結果 = "無効"; <br>} <br>return (結果); <br>} <br></script> <br> </div>