DATE日期··MATH對象

來源:互聯網
上載者:User

標籤:

1.Date日期

--Date 對象用於處理日期和時間。

Date 對象的文法:

var myDate=new Date()

2.Date 對象方法

eg:

<style type="text/css">
#date{
width: 400px;
height: 30px;
}

</style>
<body>
<input type="text" id="date">
<input type="button" value="當前日期" id="btn">
<input type="button" value="獲得年月日時分秒" id="btn1">

</body>
<script type="text/javascript">
var date=document.getElementById("date");
var btn=document.getElementById("btn");
var btn1=document.getElementById("btn1");

btn.onclick=function(){
date.value= Date();//返回當前日期
};

btn1.onclick=function(){
var nDat=new Date();
date.value=nDat.getDate();//當前月份的某一天,1--31的整數
date.value=nDat.getMonth();//月份,1--11的整數
date.value=nDat.getFullYear();//四位元年份
date.value=nDat.getHours();//小時
date.value=nDat.getMinutes();//分鐘
date.value=nDat.getSeconds();//秒
date.value=nDat.getMilliseconds();//毫秒

date.value=nDat.getMonth()+1;//月份,1--11的整數
var b=date.value;
date.value="現在時刻:"+
nDat.getFullYear()+"年"+b+"月"+nDat.getDate()+"日"+
nDat.getHours()+"點"+nDat.getMinutes()+"分" +nDat.getSeconds()+"秒"+
nDat.getMilliseconds();
};

var nDat=new Date();
var seDat= "現在時刻:"+
nDat.setFullYear(1970)+"年"+nDat.setMonth(1)+"月"+nDat.setDate(1)+"日"+
nDat.setHours(12)+"點"+nDat.setMinutes(12)+"分" +nDat.setSeconds(12)+"秒"+
nDat.setMilliseconds(12);
document.write(nDat);
</script>

3.Math 對象

--Math 對象用於執行數學任務。

Math 的屬性和方法的文法:

var pi_value=Math.PI;
var sqrt_value=Math.sqrt(15);

4.Math 對象方法

<script type="text/javascript">
document.write("PI圓周率:"+Math.PI+"<br>");
document.write("ceil上舍入(12.253):"+Math.ceil(12.253)+"<br>");
document.write("floor下舍入(12.253):"+Math.floor(12.253)+"<br>");
document.write("round四捨五入(12.253):"+Math.round(12.253)+"<br>");
document.write("round四捨五入(12.53):"+Math.round(12.53)+"<br>");
document.write("round四捨五入(-4.5):"+Math.round(-4.5)+"<br>");
document.write("round四捨五入(-4.2):"+Math.round(-4.2)+"<br>");
document.write("max最大值):"+Math.max(12,2,4,45,1)+"<br>");
document.write("max最大值(NAN)):"+Math.max("a",2,4,45,1)+"<br>");
document.write("min最小值):"+Math.min(12,2,4,45,-1)+"<br>");
document.write("min最小值(NAN)):"+Math.min("a",2,4,45,1)+"<br>");
document.write("random隨機數"+Math.random()+"<br>");

</script>

DATE日期··MATH對象

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.