Math&Date
math物件提供數學相關參數與方法供我們使用,Math內的方法都是static,所以不需要建立,直接使用Math.XXX來呼叫。Date也是內建物件,使用new關鍵字建立,可以讓我們操作時間的顯示,在之後介紹。Math properties
而其擁有的屬性如下:>>
- Math.E: Euler's number -> 2.718
- Math.LN2: Natural logarithm of 2 -> 0.693
- Math.LOG2E: Base 2 logarithm of E -> 1.442
- Math.LOG10E: Base 10 logarithm of E -> 0.434
- Math.PI: pi -> 3.14159
- Math.SQRT1_2: Square root of 1/2 -> 0.707
- Math.SQRT2: Square root of 2 -> 1.414
>>
Math methods
Math的相關方法計有如下:
- Math.abs(x): absolute value
- Math.acos(x): arccosine (in radians)
- Math.asin(x): arcsine (in radians)
- Math.atan(x): arctangent (in radians)
- Math.atan2(x,y): arctanget of the quotient of its arguments
- Math.ceil(x): smallest integer greater than of equal to x
- Math.cos(x): cosine
- Math.exp(x): ex
- Math.floor(x): largest integer less than or equal to x
- Math.log(x): logex(ln(x))
- Math.max(x,y,...): largest number
- Math.min(x,y,...): smallest number
- Math.pow(x,y): xy
- Math.random(): random number between 0 and 1
- Math.round(x): a number rounded to the nearest integer
- Math.sin(x): sine
- Math.sqrt(x): square root of x
- Math.tan(x): tangent
Date
Date的宣告方式可以有以下幾種:
- new Date()
- new Date(milliseconds): 1/1/70 + milliseconds
- new Date(datestring): "yyyy-mm-dd", "yyyy-mm", "yyyy", "yyyy-mm-ddThh:mm:ssZ"(Z:UTC time), "yyyy", "yyyy-mm-ddThh:mm:ss-hh:mm" (compare to UTC), "mm/dd/yyyy", "mmm dd yyyy" (Jul 10 2000)
- new Date(year, month, date[, hours, minutes, seconds, milliseconds])
Date methods
- Date(): today's date and time. >>
- getDate(): returns day of the month. >>
- getDay(): returns day of the week. >>
- getFullYear(): returns the year. >>
- getHours(): returns the hour. >>
- getMilliseconds(): returns milliseconds. >>
- getMinutes(): returns the minutes. >>
- getMonth(): returns the month. >>
- getSeconds(): returns the seconds. >>
- getTime(): returns the numeric value of time (milliseconds since January 1, 1970, 00:00:00 UTC). >> or use Date.parse() method or valueOf() method.
- getTimezoneOffset(): returns the time-zone offset in minutes. >>
- getUTCDate(): returns the date of the month according to universal time. >>
- getUTCDay(): returns the day of the week according to universal time. >>
- getUTCFullYear(): returns the year according to universal time. >>
- getUTCHours: returns the hours according to universal time. >>
- getUTCMilliseconds(): returns the milliseconds according to universal time. >>
- getUTCMinutes(): returns the minutes according to universal time. >>
- getUTCMonth(): returns the month according to universal time. >>
- getUTCSeconds(): returns the seconds according to universal time. >>
- setDate(): sets the day of month. >>
- setFullYear(): sets the year. >>
- setHours(): sets the hour. >>
- setMilliseconds(): sets the Milliseconds. >>
- setMinutes(): sets the Minutes. >>
- setMonth(): sets the Month. >>
- setSeconds(): sets the Seconds. >>
- setTime(): sets the Date object to the time represented by a milliseconds >>
- setUTCDate(): sets the day of the month according to universal time. >>
- setUTCFullYear(): sets the year according to universal time. >>
- setUTCHours(): sets the hour according to universal time. >>
- setUTCMilliseconds(): sets the milliseconds according to universal time. >>
- setUTCMinutes(): sets the minutes according to universal time. >>
- setUTCMonth(): sets the month according to universal time. >>
- setUTCSeconds(): sets the seconds according to universal time. >>
- toDateString(): returns date. >>
- toLocaleDateString(): returns date using current locale's conventions. >>
- toLocaleString(): converts a date to a string, using current locale's conventions. >>
- toLocaleTimeString(): returns the time of the Date, using current locale's conventions. >>
- toString(): returns a String of a Date object. >>
- toTimeString(): returns a String of time of a Date object. >>
- toUTCString(): returns a String of time of a Date object according to universal time. >>
Time Comparison
比較兩時間的先後。 >>