zoukankan      html  css  js  c++  java
  • JavaScript -- 常用的日期对象和数学对象

    创建一个时间对象

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

    常用方法

    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) 的分钟差。
    
    

    数学对象

    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无1
    
    Math.pow(x,y);      //x的y次幂
    

    求一个min-max的随机数(且包括min和max):

    function random(min,max){
        return Math.round(Math.random()*(max-min)+min);
    }
    
  • 相关阅读:
    PHP下实现两种ajax跨域的解决方案之jsonp
    实际应用中git(合并本地与服务器项目)
    centos7 编译安装nginx
    windows vagrant共享目录设置问题
    shell 需要注意的点
    插入排序(直接插入排序)
    选择排序
    快速排序
    冒泡排序
    centos7.5安装redis-5.0.4
  • 原文地址:https://www.cnblogs.com/adoctors/p/9064222.html
Copyright © 2011-2022 走看看