JavaScript--Common date objects and math objects

Source: Internet
Author: User

Create a Time object

var time=new Date();   //当前时间,()内可写入字符串 ,如‘2017-10-10‘,可转为响应的时间

Common methods

time.getFullYear();  //从 Date 对象以四位数字返回年份。time.getMonth();    //从 Date 对象返回月份 (0 ~ 11)。time.getDate();     //从 Date 对象返回一个月中的某一天 (1 ~ 31)。time.getDay();     //从 Date 对象返回一周中的某一天 (0 ~ 6)。周日为0;time.getHours();   //返回 Date 对象的小时 (0 ~ 23)。time.getMinutes();     //返回 Date 对象的分钟 (0 ~ 59)。time.getSeconds();     //返回 Date 对象的秒数 (0 ~ 59)。time.getMilliseconds();    //返回 Date 对象的毫秒(0 ~ 999)。time.getTime();        //返回 1970 年 1 月 1 日至今的毫秒数。time.getTimezoneOffset();  //返回本地时间与格林威治标准时间 (GMT) 的分钟差。
Mathematical objects
Math.abs(x);        //返回数的绝对值。Math.ceil(x);       //进一取整Math.floor(x);      //退一取整Math.min(x,y);      //取最小值Math.max(x,y);      //取最大值Math.round(x);      //四舍五入Math.random();      //0-1见的随机数,有0无1Math.pow(x,y);      //x的y次幂

Find a random number of Min-max (and include Min and Max):

function random(min,max){    return Math.round(Math.random()*(max-min)+min);}

JavaScript--Common date objects and math objects

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.