Javascript_core, Math, Date

Source: Internet
Author: User
Tags local time

Javascript_core, Math, Date

1. Regexp:regular expression, create the encapsulated regular expressions:

① Direct Volume: var reg=/reg/ig;②var reg=new RegExp ("Reg", "IG");

2. RegExp API:

① find each keyword and get location: var arr=reg.exec (str); default search from the beginning;

return value: arr: "keywords",1,1,2,$3 ... ";

Arr.index: This time to find the location of keywords;

Find: Reg.lastindex: Where to start next;

RegExp. $n: The nth grouping of the keywords;

3. Verification: Var bool=reg.test (str); returns a Boolean value;

4. Math:

①: Math.ceil (num), ② down: Math.floor (num), ③ rounded rounding: Math.Round (num), ④ rounded by any decimal place: n.tofixed (d); ⑤ Power: Math.pow (base, exponentiation); ⑥ Open Square: math.sq RT (num); ⑦ max: Math.max (value 1, value 2 ...) ); ⑧ Minimum Value: math.min (value 1, value 2 ...). ); ⑨ gets the maximum value in the array: Math.max.apply (Null,arr); 10 Gets the minimum value in the array: Math.min.apply (Null,arr); 11 Random number: Math.random (); generating decimals between 0~1 ; 12 random Number: parseint (Math.random () * (max-min+1) +min);

5, Date: Encapsulation operation time API, the number of milliseconds since January 1, 1970;

Create: ① Create Date object, automatically get client system time: var now=new date (), ② create Date object, and custom time: var date=new date ("Year/month/date hours:minutes:seconds") or var date=new date (year,month-1,date,hours,minutes,second); ③ copy Date object: var date2=new date (date1);

6. Date API:

① component: Fullyear,month,date,day (week), Hours,minutes,seconds,milliseconds;

② method: GetXXX: Gets the value of the specified component; Setxxx modifies the value of the specified component;

③ calculation: The date subtraction result is the number of milliseconds; Date.setxxx (Date.getxxx () +/-n);

④ to String:

Convert date to International standard date format: date.tostring ();

Converted to local time format: date.tolocalestring ();

Retention Date only: Date.tolocaledatestring ();

Retention time only: date.tolocaletimestring ();

This article reprint address:http://www.cnblogs.com/Jupiter258/

Javascript_core, Math, Date

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.