Date Object
1. What is a Date object?
Date objects can store any one date, and can be accurate to milliseconds (1/1000 seconds).
Syntax: var udate=new Date ();
Note: The initial value is the current time (current computer system time).
2.Date Objects Common methods:
3.Date Method Instance
Copy Code code as follows:
var newtime=new date ();//Get current time
var millsecond=date.now ()//the number of milliseconds converted to the current date
var fullyear=newtime.getfullyear ()//Get Year
var year=newtime.getyear ()//Get Year
var month=newtime.getmonth ()//Get month return 0-11 0 means January 11 for December
var week=newtime.getday ();//Get the number of weeks returned is 0-6, 0 for Sunday
var today=newtime.getdate ();//Get today's date
var hours=newtime.gethours ();//Get Number of hours
var minutes=newtime.getminutes ();//Get minutes
var seconds=newtime.getseconds ();//Get number of seconds
Console.log (newtime);//Wed Feb 2015 10:54:17 gmt+0800 (China Standard Time)
Console.log (Millsecond);//1423029309565
Console.log (fullyear);//2015
Console.log (year);//115
Console.log (month);//1 said February
Console.log (week);//3 said Wednesday
Console.log (today),//4, No. 4th
Console.log (hours);//10 hours
Console.log (minutes);//54 minutes
Console.log (seconds);//17 second
Math Object
1. What is a Math object ?
The Math object that provides a mathematical calculation of the data.
Note: The Math object is an intrinsic object that you can call all its properties and methods without creating it and using math as an object directly. This is the difference between it and the Date,string object.
Properties and methods of 2.Math objects
Math Object Properties
Math Object method
3.Math Object Individual Method instance
1): The Ceil () method is rounded up to return an integer that is greater than or equal to X and is closest to X.
Copy Code code as follows:
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): The Floor () method is rounded down to return an integer that is less than or equal to X and is closest to X.
Copy Code code as follows:
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 () method to round a number to the nearest integer
Copy Code code as follows:
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): The Random () method returns a random number between 0 ~ 1 (greater than or equal to 0 but less than 1).
Copy Code code as follows:
document.write (Math.random ())//returns 0 to 1 numbers excluding 1
document.write (Math.random () *10);//return numbers from 0 to 10 excluding 10
5): Min () method: Returns the smallest value in a set of values
Copy Code code as follows:
document.write (Math.min (2,3,4,6));//2
Gets the minimum value in the array, using the Apply () method:
Copy Code code as follows:
var values=[3,2,1,8,9,7];
document.write (Math.min.apply (math,values) + "<br>");//1
The Math object is the first argument to apply, and any array as the second argument
6): Max () Method: Returns the maximum value in a set of values
Copy Code code as follows:
document.write (Math.max (2,3,4,6));//6
Gets the minimum value in the array, using the Apply () method:
Copy Code code as follows:
var values=[3,2,1,8,9,7];
document.write (Math.max.apply (math,values) + "<br>");//9
The above is about the date (Date object) in JavaScript, the entire contents of the Math object, I hope you can enjoy it.