<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>return date; <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.minute = newCom.getMinutes(); <BR>this.second = newCom.getSeconds(); <BR>this.msecond = newCom.getMilliseconds(); <BR>this.week = newCom.getDay(); <BR>} <BR>function DateDiff(interval, date1, date2) { <BR>var TimeCom1 = new TimeCom(date1); <BR>var TimeCom2 = new TimeCom(date2); <BR>var result; <BR>switch (String(interval).toLowerCase()) { <BR>case "y": <BR>case "year": <BR>result = TimeCom1.year - TimeCom2.year; <BR>break; <BR>case "m": <BR>case "month": <BR>result = (TimeCom1.year - TimeCom2.year) * 12 + (TimeCom1.month - TimeCom2.month); <BR>break; <BR>case "d": <BR>case "day": <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)); <BR>break; <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>break; <BR>case "min": <BR>case "minute": <BR>result = Math.round((Date.UTC(TimeCom1.year, TimeCom1.month - 1, TimeCom1.day, TimeCom1.hour, TimeCom1.minute) - Date.UTC(TimeCom2.year, TimeCom2.month - 1, TimeCom2.day, TimeCom2.hour, TimeCom2.minute)) / (1000 * 60)); <BR>break; <BR>case "s": <BR>case "second": <BR>result = Math.round((Date.UTC(TimeCom1.year, TimeCom1.month - 1, TimeCom1.day, TimeCom1.hour, TimeCom1.minute, TimeCom1.second) - Date.UTC(TimeCom2.year, TimeCom2.month - 1, TimeCom2.day, TimeCom2.hour, TimeCom2.minute, TimeCom2.second)) / 1000); <BR>break; <BR>case "ms": <BR>case "msecond": <BR>result = Date.UTC(TimeCom1.year, TimeCom1.month - 1, TimeCom1.day, TimeCom1.hour, TimeCom1.minute, TimeCom1.second, TimeCom1.msecond) - Date.UTC(TimeCom2.year, TimeCom2.month - 1, TimeCom2.day, TimeCom2.hour, TimeCom2.minute, TimeCom2.second, TimeCom1.msecond); <BR>break; <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>break; <BR>default: <BR>result = "invalid"; <BR>} <BR>return (result); <BR>} <BR></script> <br> </div>