只在此山中,雲深不知處


聽首歌



© 2018 by Shawn Huang
Last Updated: 2018.5.27

Math&Date

math物件提供數學相關參數與方法供我們使用,Math內的方法都是static,所以不需要建立,直接使用Math.XXX來呼叫。Date也是內建物件,使用new關鍵字建立,可以讓我們操作時間的顯示,在之後介紹。

Math properties


而其擁有的屬性如下:>>
  1. Math.E: Euler's number -> 2.718
  2. Math.LN2: Natural logarithm of 2 -> 0.693
  3. Math.LOG2E: Base 2 logarithm of E -> 1.442
  4. Math.LOG10E: Base 10 logarithm of E -> 0.434
  5. Math.PI: pi -> 3.14159
  6. Math.SQRT1_2: Square root of 1/2 -> 0.707
  7. Math.SQRT2: Square root of 2 -> 1.414

>>

Math methods


Math的相關方法計有如下:
  1. Math.abs(x): absolute value
  2. Math.acos(x): arccosine (in radians)
  3. Math.asin(x): arcsine (in radians)
  4. Math.atan(x): arctangent (in radians)
  5. Math.atan2(x,y): arctanget of the quotient of its arguments
  6. Math.ceil(x): smallest integer greater than of equal to x
  7. Math.cos(x): cosine
  8. Math.exp(x): ex
  9. Math.floor(x): largest integer less than or equal to x
  10. Math.log(x): logex(ln(x))
  11. Math.max(x,y,...): largest number
  12. Math.min(x,y,...): smallest number
  13. Math.pow(x,y): xy
  14. Math.random(): random number between 0 and 1
  15. Math.round(x): a number rounded to the nearest integer
  16. Math.sin(x): sine
  17. Math.sqrt(x): square root of x
  18. Math.tan(x): tangent

Date


Date的宣告方式可以有以下幾種:

Date methods

  1. Date(): today's date and time. >>
  2. getDate(): returns day of the month. >>
  3. getDay(): returns day of the week. >>
  4. getFullYear(): returns the year. >>
  5. getHours(): returns the hour. >>
  6. getMilliseconds(): returns milliseconds. >>
  7. getMinutes(): returns the minutes. >>
  8. getMonth(): returns the month. >>
  9. getSeconds(): returns the seconds. >>
  10. getTime(): returns the numeric value of time (milliseconds since January 1, 1970, 00:00:00 UTC). >> or use Date.parse() method or valueOf() method.
  11. getTimezoneOffset(): returns the time-zone offset in minutes. >>
  12. getUTCDate(): returns the date of the month according to universal time. >>
  13. getUTCDay(): returns the day of the week according to universal time. >>
  14. getUTCFullYear(): returns the year according to universal time. >>
  15. getUTCHours: returns the hours according to universal time. >>
  16. getUTCMilliseconds(): returns the milliseconds according to universal time. >>
  17. getUTCMinutes(): returns the minutes according to universal time. >>
  18. getUTCMonth(): returns the month according to universal time. >>
  19. getUTCSeconds(): returns the seconds according to universal time. >>
  20. setDate(): sets the day of month. >>
  21. setFullYear(): sets the year. >>
  22. setHours(): sets the hour. >>
  23. setMilliseconds(): sets the Milliseconds. >>
  24. setMinutes(): sets the Minutes. >>
  25. setMonth(): sets the Month. >>
  26. setSeconds(): sets the Seconds. >>
  27. setTime(): sets the Date object to the time represented by a milliseconds >>
  28. setUTCDate(): sets the day of the month according to universal time. >>
  29. setUTCFullYear(): sets the year according to universal time. >>
  30. setUTCHours(): sets the hour according to universal time. >>
  31. setUTCMilliseconds(): sets the milliseconds according to universal time. >>
  32. setUTCMinutes(): sets the minutes according to universal time. >>
  33. setUTCMonth(): sets the month according to universal time. >>
  34. setUTCSeconds(): sets the seconds according to universal time. >>
  35. toDateString(): returns date. >>
  36. toLocaleDateString(): returns date using current locale's conventions. >>
  37. toLocaleString(): converts a date to a string, using current locale's conventions. >>
  38. toLocaleTimeString(): returns the time of the Date, using current locale's conventions. >>
  39. toString(): returns a String of a Date object. >>
  40. toTimeString(): returns a String of time of a Date object. >>
  41. toUTCString(): returns a String of time of a Date object according to universal time. >>

Time Comparison


比較兩時間的先後。 >>