1. built-in objects

A, Math objects:

1. absolute value: Math.abs ()

2. The three rounding methods:

Math.floor () rounds down to the floor of the small value of

Math.ceil () rounded up to the ceiling of a large value of

Math.round () rounding other numbers are rounded, but .5 special, which to a large value

例:Math.round( -1.5 );  // -1

  Math.round( 1.5 );  // 2

3. Random Number

Math.random () returns a random decimal 0 <= x <1

Case: random number between two numbers, and contains these two numbers;

getRandom functions (min, max) {

  return Math.floor( Math.random() * ( max - min +1) ) + min ;

}

getRandom (1.10);  

 

Two, Date Object

1, the common method of Date

 getFullYear (); // Get the current year

 getMonth (); // Get the current month (0-11)

 getDate (); // get today's date

 getDay (); // get the week (Sunday to Saturday 6 0)

 getHours (); // Get the current hour

 getMinutes (); // Get the current minute

 getSeconds (); // Get the current seconds

2. There are four ways to obtain the total number of milliseconds: 

 1. getTime () or valueOf ()

 var date = new Date();

 date.getTime( );

 date.valueOf( );

 2. Common wording

 var  date1 = +new Date( );

 3.H5 new (not considering browser compatibility)

 Date.now( );

Guess you like

Origin www.cnblogs.com/qtbb/p/11577942.html