JavaScript学习-Math与Date对象

    Math对象是一个静态对象,不能使用new关键字创建对象实例,应直接使用"对象名.成员"的格式来访问其属性或方法。
Math中的属性说明:
E 属性:代表数字常数e,自然对数的底。E 属性约等于 2.718。
LN2 属性:返回 2 的自然对数。
LN10 属性:返回 10 的自然对数。
LOG2E 属性:返回 以 2 为底 e(自然对数的底)的对数。
LOG10E 属性:返回以 10 为底 e(自然对数的底)的对数。
PI 属性:返回圆的周长与其直径的比值,约等于 3.141592653589793。
SQRT1_2 属性:返回 0.5 的平方根,或说 2 的平方根分之一。
SQRT2 属性:返回 2 的平方根。

Math中的方法说明:
abs 方法:返回数字的绝对值。
acos 方法:返回数的反余弦值。
asin 方法:返回数字的反正弦值。
atan 方法:返回数字的反正切值。
atan2 方法:返回由 X 轴到 (y,x) 点的角度(以弧度为单位)。
ceil 方法:返回大于等于其数字参数的最小整数。
cos 方法:返回数的余弦值。
exp 方法:返回 e(自然对数的底)的幂。
floor 方法:返回小于等于其数值参数的最大整数。
log 方法:返回数字的自然对数。
max 方法:返回给出的零个或多个数值表达式中较大者。
min 方法:返回给出的零个或多个数值表达式中较小的值。
pow 方法:返回底表达式的指定次幂。
random 方法:返回介于 0 和 1 之间的伪随机数。
round 方法:返回与给出的数值表达式最接近的整数。
sin 方法:返回数字的正弦值。
sqrt 方法:返回数字的平方根。
tan 方法:返回数字的正切值。


Date对象:
构造函数:
dateObj = new Date()
dateObj = new Date(dateVal)//构造函数1
dateObj = new Date(year, month, date[, hours[, minutes[, seconds[,ms]]]]) //构造函数2
Date用法举例:
   <% -- JavaScript学习 -- %>
    
< script  type ="text/javascript"  language ="JavaScript" >  
        
function  DemoDate()
        {   
            
var  sStr;
            
var  dDate = new  Date();  
            sStr
= dDate.getYear() + " " ;
            sStr
+= dDate.getMonth() + " " ;
            sStr
+= dDate.getDate() + " " ;
            sStr
+= dDate.getHours() + " " ;
            sStr
+= dDate.getMinutes() + " " ;
            sStr
+= dDate.getSeconds() + " " ;           
            
return  sStr;
        }
    
        
function  DemoDatePhrase()
        {   
            
var  datestring  =   " November 1, 1997 10:15 AM "
            datestring
= Date.parse(datestring);
            
var  dDate = new  Date(datestring);
            
var  sStr;
            sStr
= dDate.getYear() + " " ;
            
// getMonth 方法返回一个处于 0 到 11 之间的整数,它代表 Date 对象中的月份值。这个整数并不等于按照惯例来表示月份的数字,而是要比按惯例表示的值小 1。
            sStr = (dDate.getMonth() + 1 ) + " " ;
            sStr
+= dDate.getDate() + " " ;
            sStr
+= dDate.getHours() + " " ;
            sStr
+= dDate.getMinutes() + " " ;
            sStr
+= dDate.getSeconds() + " " ;           
            alert(
" 日期为: " + sStr);
        }
        
function  PersionShow()
        {
            
// 调用函数
            alert( " 日期为: " + DemoDate());
            
        }
    
</ script >

            
<% -- 测试使用的按钮 -- %>
            
< input  id ="Button1"  type ="button"  runat ="server"  value ="测试"  onclick ="PersionShow();"   />
            
< input  id ="Button2"  type ="button"  runat ="server"  value ="测试Phrase"  onclick ="DemoDatePhrase();"   />

 

Data对象中的方法说明:

getDate 方法:返回 Date 对象中用本地时间表示的一个月中的日期值。
getDay 方法: 返回 Date 对象中用本地时间表示的一周中的日期值。
getFullYear 方法 :返回 Date 对象中用本地时间表示的年份值。
getHours 方法:返回 Date 对象中用本地时间表示的小时值。
getMilliseconds 方法 :返回 Date 对象中用本地时间表示的毫秒值。
getMinutes 方法:返回 Date 对象中用本地时间表示的分钟值。
getMonth 方法:返回 Date 对象中用本地时间表示的月份值。
getSeconds 方法: 返回 Date 对象中用本地时间表示的秒钟值。
getTime 方法 :返回 Date 对象中的时间值。
getTimezoneOffset 方法:返回用分钟表示的主计算机上的时间和全球标准时间 (UTC)之间的差别。
getUTCDate 方法 :返回 Date 对象中用全球标准时间 (UTC)表示的日期。
getUTCDay 方法 :返回 Date 对象中用全球标准时间 (UTC)表示的一周中的日期值。
getUTCFullYear 方法:返回 Date 对象中用全球标准时间 (UTC)表示的年份值。
getUTCHours 方法 :返回 Date 对象中用全球标准时间 (UTC)表示的小时值。
getUTCMilliSeconds 方法: 返回 Date 对象中用全球标准时间 (UTC)表示的毫秒值。
getUTCMinutes 方法 :返回 Date 对象中用全球标准时间 (UTC)表示的分钟值。
getUTCMonth 方法:返回 Date 对象中用全球标准时间 (UTC)表示的月份值。
getUTCSeconds 方法 :返回 Date 对象中用全球标准时间 (UTC)表示的秒钟值。
getVarDate 方法 :返回 Date 对象中的 VT_DATE 值。
getYear 方法 :返回 Date 对象中的年份值。
setDate 方法 :设置 Date 对象中用本地时间表示的数字日期。
setFullYear 方法: 设置 Date 对象中用本地时间表示的年份值。
setHours 方法 :设置 Date 对象中用本地时间表示的小时值。
setMilliSeconds 方法: 设置 Date 对象中用本地时间表示的毫秒值。
setMinutes 方法 :设置 Date 对象中用 本地时间表示的分钟值。
setMonth 方法 :设置 Date 对象中用 本地时间表示的月份值。
setSeconds 方法 :设置 Date 对象中用 本地时间表示的秒钟值。
setTime 方法 :设置 Date 对象的日期和时间值。
setUTCDate 方法: 设置 Date 对象中用全球标准时间 (UTC)表示的数值日期。
setUTCFullYear 方法:设置 Date 对象中用全球标准时间 (UTC)表示的年份值。
setUTCHours 方法 :设置 Date 对象中用全球标准时间 (UTC)表示的小时值。
setUTCMilliseconds 方法:设置 Date 对象中用全球标准时间 (UTC)表示的毫秒值。
setUTCMinutes 方法 :设置 Date 对象中用全球标准时间 (UTC)表示的分钟值。
setUTCMonth 方法 :设置 Date 对象中用 全球标准时间 (UTC)表示的月份值。
setUTCSeconds 方法 :设置 Date 对象中用全球标准时间 (UTC)表示的秒值。
setYear 方法 :设置 Date 对象中的年份值。
toGMTString 方法 :返回一个日期,该日期用格林威治标准时间 (GMT) 表示并已被转换为字符串。
toLocaleString 方法: 返回一个日期,该日期使用当前区域设置并已被转换为字符串。
toUTCString 方法 :返回一个已被转换为字符串的,用全球标准时间 (UTC)表示的日期。
toString 方法 :返回对象的字符串表示。
valueOf 方法 :返回指定对象的原始值。
parse 方法 :解析一个包含日期的字符串,并返回该日期与 1970 年 1 月 1 日午夜之间所间隔的毫秒数。
UTC 方法:返回全球标准时间 (UTC) (或 GMT) 的 1970 年 1 月 1 日到所指定日期之间所间隔的毫秒数。

你可能感兴趣的:(JavaScript)