Date Dates · Math Object

Source: Internet
Author: User

1.Date Date

The--date object is used to process dates and times.

Syntax for the Date object:

var mydate=new Date ()

2.Date Object Methods

eg

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

</style>
<body>
<input type= "text" id= "date" >
<input type= "button" value= "Current date" 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 ();//return current date
};

Btn1.onclick=function () {
var ndat=new Date ();
Date.value=ndat.getdate ();//a day of the current month, an integer of 1--31
Date.value=ndat.getmonth ();//month, 1--11 integer
Date.value=ndat.getfullyear ();//four-digit year
Date.value=ndat.gethours ();//hour
Date.value=ndat.getminutes ();//min
Date.value=ndat.getseconds ();//sec
Date.value=ndat.getmilliseconds ();//milliseconds

Date.value=ndat.getmonth () +1;//month, 1--11 integer
var B=date.value;
Date.value= "Present moment:" +
Ndat.getfullyear () + "year" +b+ "month" +ndat.getdate () + "Day" +
Ndat.gethours () + "point" +ndat.getminutes () + "Min" +ndat.getseconds () + "seconds" +
Ndat.getmilliseconds ();
};

var ndat=new Date ();
var sedat= "Now moment:" +
Ndat.setfullyear (1970) + "Year" +ndat.setmonth (1) + "Month" +ndat.setdate (1) + "Day" +
Ndat.sethours (12) + "point" +ndat.setminutes (12) + "Min" +ndat.setseconds (12) + "seconds" +
Ndat.setmilliseconds (12);
document.write (Ndat);
</script>

3.Math objects

The--math object is used to perform mathematical tasks.

Syntax for the properties and methods of Math:

var Pi_value=math.pi;
var sqrt_value=math.sqrt (15);

4.Math Object Methods

<script type= "Text/javascript" >
document.write ("Pi pi:" +math.pi+ "<br>");
document.write ("Ceil Rounding (12.253):" +math.ceil (12.253) + "<br>");
document.write ("Floor Rounding (12.253):" +math.floor (12.253) + "<br>");
document.write ("Round Rounding (12.253):" +math.round (12.253) + "<br>");
document.write ("Round Rounding (12.53):" +math.round (12.53) + "<br>");
document.write ("Round Rounding ( -4.5):" +math.round ( -4.5) + "<br>");
document.write ("Round Rounding ( -4.2):" +math.round ( -4.2) + "<br>");
document.write ("Max Max"): "+math.max (12,2,4,45,1) +" <br> ");
document.write ("Max Maximum (NAN)"): "+math.max (" a ", 2,4,45,1) +" <br> ");
document.write ("Min min"): "+math.min (12,2,4,45,-1) +" <br> ");
document.write (Min min (NAN)): "+math.min (" a ", 2,4,45,1) +" <br> ");
document.write ("Random Number" +math.random () + "<br>");

</script>

Date Dates · Math Object

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.