JavaScript date

xiaoxiao2021-04-09  346

FUNCTION

Timecom (DateValue)

{Var newcom = new Date (DateValue); this.Year = newcom.getyear (); this.month = newcom.getMonth () 1; this.day = newcom.getdate (); this.Hour = newcom.gethours ); This.minute = newcom.getminutes (); this.second = newcom.getseconds (); this.msecond = newcom.getMilliseConds (); this.Week = newcom.getday ();}

FUNCTION

Datediff (Interval, Date1, Date2)

{Var timecom1 = new timecom (date1); var timecom2 = new timecom (date2); var result; switch (interface (interval) .tolowercase ()) {copy "y": case "year": result = timecom1.year- TimeCom2.year; break; case "n": case "month": result = (timecom1.year-timecom2.year) * 12 (timecom1.month-timecom2.month); Break; Case "D": Case "Day ": Result = math.round ((time.utc (timecom1.year, timecom1.month-1, timecom1.day) -date.utc (timecom2.year, timecom2.month-1, timecom2.day) / (1000 * 60 * 60 * 24)); Break; Case "H": Case "hour": 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)); Break; Case "M": Case "Minute": 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 ))); Break; case "s": case "second": 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); Break; Case "MS": Case "msecond": 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; break; case "w": Case "week": result = math.round ((timecom1.year, timecom1.month -1, timecom1.day) -date.utc (timecom2.year, timecom2.month-1, timecom2.day) / (1000 * 60 * 60 * 24))% 7; Break; default: result = "invalid" } Return (result);} function

Dateadd (Interval, Num, DateValue)

{Var newcom = new timeCom (String (Interval) .tolowercase ()) {copy "y": case "year": newcom.Year = Num; Break; Case "N": Case "MONTH" : Newcom.month = Num; Break; Case "D": Case "day": newcom.day = Num; Break; Case "H": Case "Hour": newcom.hour = Num; Break; Case M: Case "minute": newcom.minute = Num; break; case "s": case "second": newcom.second = Num; Break; Case "MS": Case "msecond": newcom.msecond = Num; Break; Case "W": Case "WEEK": newcom.day = Num * 7; Break; default: return ("invalid");} var now = newcom.Year "/" newcom.month " / " Newcom. Hour ": " newcom.minute ": " new service (now);}

转载请注明原文地址:https://www.9cbs.com/read-133168.html

New Post(0)