最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

淺談JavaScript中Date(日期對象),Math對象

 更新時(shí)間:2015年02月05日 10:21:34   投稿:hebedich  
這篇文章主要簡單介紹了JavaScript中Date(日期對象),Math對象的相關(guān)資料,需要的朋友可以參考下

Date對象

1.什么是Date對象?

日期對象可以儲存任意一個日期,并且可以精確到毫秒數(shù)(1/1000 秒)。

語法:var Udate=new Date();

注:初始值為當(dāng)前時(shí)間(當(dāng)前電腦系統(tǒng)時(shí)間)。

2.Date對象常用方法:

3.Date方法實(shí)例

復(fù)制代碼 代碼如下:

var newTime=new Date();//獲取當(dāng)前時(shí)間
            var millSecond=Date.now();//當(dāng)前日期轉(zhuǎn)換成的毫秒數(shù)
            var fullYear=newTime.getFullYear();//獲取年份
            var year=newTime.getYear();//獲取年份
            var month=newTime.getMonth();//獲取月份 返回0-11 0表示一月 11表示十二月
            var week=newTime.getDay();//獲取星期幾  返回的是0-6的數(shù)字,0 表示星期天
            var today=newTime.getDate();//獲取當(dāng)天日期
            var hours=newTime.getHours();//獲取小時(shí)數(shù)
            var minutes=newTime.getMinutes();//獲取分鐘數(shù)
            var seconds=newTime.getSeconds();//獲取秒數(shù)
            console.log(newTime);// Wed Feb 04 2015 10:54:17 GMT+0800 (中國標(biāo)準(zhǔn)時(shí)間)
            console.log(millSecond);// 1423029309565
            console.log(fullYear);// 2015
            console.log(year);//115
            console.log(month);//1 表示2月
            console.log(week);//3 表示星期三
            console.log(today);//4 4號
            console.log(hours);//10小時(shí)
            console.log(minutes);//54分鐘
            console.log(seconds);//17秒

Math對象

1.什么是Math對象

Math對象,提供對數(shù)據(jù)的數(shù)學(xué)計(jì)算。

注意:Math 對象是一個固有的對象,無需創(chuàng)建它,直接把 Math 作為對象使用就可以調(diào)用其所有屬性和方法。這是它與Date,String對象的區(qū)別。

2.Math對象的屬性和方法

Math對象屬性

Math對象方法

3.Math對象個別方法實(shí)例

1):ceil()方法向上取整,返回的是大于或等于x,并且與x最接近的整數(shù)。

復(fù)制代碼 代碼如下:

 document.write(Math.ceil(0.8) + "<br />")//1
 document.write(Math.ceil(6.3) + "<br />")//7
 document.write(Math.ceil(5) + "<br />")//5
 document.write(Math.ceil(3.5) + "<br />")//4
 document.write(Math.ceil(-5.1) + "<br />")//-5
 document.write(Math.ceil(-5.9))//-5

2):floor()方法向下取整,返回的是小于或等于x,并且與x最接近的整數(shù)。

復(fù)制代碼 代碼如下:

document.write(Math.floor(0.8) + "<br />")//0
document.write(Math.floor(6.3) + "<br />")//6
document.write(Math.floor(5) + "<br />")//5
document.write(Math.floor(3.5) + "<br />")//3
document.write(Math.floor(-5.1) + "<br />")//-6
document.write(Math.floor(-5.9))//-6

3):round() 方法可把一個數(shù)字四舍五入為最接近的整數(shù)

復(fù)制代碼 代碼如下:

document.write(Math.round(0.8) + "<br />")//1
document.write(Math.round(6.3) + "<br />")//6
document.write(Math.round(5) + "<br />")//5
document.write(Math.round(3.5) + "<br />")//4
document.write(Math.round(-5.1) + "<br />")//-5
document.write(Math.round(-5.9)+"<br />")//-6

4):random() 方法可返回介于 0 ~ 1(大于或等于 0 但小于 1 )之間的一個隨機(jī)數(shù)。

復(fù)制代碼 代碼如下:

document.write(Math.random());//返回0到1之間的數(shù)字 不包括1
document.write(Math.random()*10);//返回0到10之間的數(shù)字 不包括10

5):min()方法:返回一組數(shù)值中的最小值

復(fù)制代碼 代碼如下:

document.write(Math.min(2,3,4,6));//2

 獲取數(shù)組中最小值,使用apply()方法:

復(fù)制代碼 代碼如下:

var values=[3,2,1,8,9,7];
document.write(Math.min.apply(Math,values)+"<br>");//1

Math對象作為apply第一個參數(shù),任意數(shù)組作為第二參數(shù)

6):max()方法:返回一組數(shù)值中的最大值

復(fù)制代碼 代碼如下:

document.write(Math.max(2,3,4,6));//6

 獲取數(shù)組中最小值,使用apply()方法:

復(fù)制代碼 代碼如下:

var values=[3,2,1,8,9,7];
document.write(Math.max.apply(Math,values)+"<br>");//9

以上就是關(guān)于JavaScript中Date(日期對象),Math對象的全部內(nèi)容了,希望大家能夠喜歡。

相關(guān)文章

最新評論

台北县| 确山县| 泸定县| 崇左市| 淮南市| 东山县| 鹿泉市| 高州市| 宁波市| 广饶县| 乐东| 承德市| 区。| 永福县| 甘洛县| 台东市| 霍州市| 邛崃市| 尼勒克县| 堆龙德庆县| 玛曲县| 宿迁市| 鄂托克前旗| 高邮市| 宁城县| 腾冲县| 吐鲁番市| 清原| 安义县| 安国市| 阿合奇县| 金湖县| 绿春县| 和静县| 兴仁县| 罗江县| 宜兰县| 扶风县| 浙江省| 阜康市| 东乌|