JS Date Math Number

Source: Internet
Author: User

Date Object

The Date object, unlike the string object, defines a string that, in fact, is a string object that can call properties and methods directly.

The use of the Date object must be created with the new keyword, otherwise the properties and methods of the date object cannot be called.

Create Date methods of the object

(1 ) Create current ( now) An instance of a Date object with no parameters

        var timer = new Date ();

    (2) Create a Date object instance of the specified timestamp, the parameter is a timestamp

Timestamp: Refers to the number of millisecond values (1 seconds =1000 milliseconds) that have elapsed in the past, 0 seconds from January 1, 1970 0:0.

var timer = new Date (10000); Time is January 1, 1970 0:0 10 seconds

(3 Specifies a date-time information for a string that is a datetime string

var timer = new Date ("2015/5/25 10:00:00");

    (4 ) to specify multiple numeric parameters

var timer = new Date (2015+100,4,25,10,20,0);

The order is: year, month, day, time, minute, second, year, month, day is necessary.

getFullYear (): Gets the four-bit year.

GetMonth (): Gets the month, with a value of 0-11.

GetDate (): Gets the number, takes the value 1-31

GetHours (): Gets the number of hours.

Getminutes (): Number of minutes

Getseconds (): Number of seconds

Getmilliseconds () MS

GetDay () Week

GetTime () millisecond value, the millisecond value from January 1, 1970 to the present

Math Mathematical Object

The Math object is a static object, in other words: When you use the Math object, you do not need to create an instance.

Math.PI: Pi.

Math.Abs (): absolute value. Example: Math.Abs (-9) = 9

Math.ceil (): Rounding up (integers plus 1, decimals removed). Example: Math.ceil (10.2) = 11

Math.floor (): Rounding down (directly minus decimals). Example: Math.floor (9.888) = 9

Math.Round (): Rounded.    such as: Math.Round (4.5) = 5; Math.Round (4.1) = 4

Math.pow (x, y): X is the y-square. Example: Math.pow (2,3) = 8

MATH.SQRT (): To find the square root. Example: math.sqrt (121) = 11

Math.random (): Returns a random decimal number between 0 and 1. Example: math.random () = 0.12204467732259783

A random integer between 0-10, a random integer between 10-20 and a random integer between 20 and 30; Find a random integer between 7 and 91

  

  

Number Numeric Object

A numeric variable, which is a numeric object (number Object).

ToFixed ()

Function: Converts a numeric value to a string and rounds it, preserving a decimal number of the specified digits.

Syntax: numobj.tofixed (n)

Parameter: N is the number of decimal digits to keep.

Example:

var a = 123.9878;

A = a.tofixed (2); A = "123.99"

JS Date Math Number

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.