zoukankan      html  css  js  c++  java
  • js中的数学对象、日期、定时器

    1、数学对象 Math
      特点 :不需要定义  直接通过 Math. 调用方法
        Math.pow(m,n) m的n次幂
        Math.sqrt(m) 平方根     勾股定理 : c = Math.sqrt(Math.pow(a,2) + Math.pow(b,2))
        Math.abs(m) 绝对值
        Math.floor(m)  向下取整  (小于m的最大整数)
        Math.ceil(m) 向上取整   (大于m的最小整数)
        Math.round() 四舍五入 
        Math.max() 获取最大值
        Math.min() 获取最小值
        Math.random()  [0,1)  获取0--1之间的随机小数   如何利用随机数获取任意区间整数值
      获取任意区间值整数的函数:
        function rand(min,max){
            return Math.round( Math.random()*(max-min) + min );
        }
    2、日期时间对象 Date

      getFullYear() 年
      getMonth() 月 d.getMonth()+1 月份从0开始
      getDate() 日期 从 Date 对象返回一周中的某一天 (0 ~ 6)。
      getHours() 返回 Date 对象的小时 (0 ~ 23)。
      getMinutes() 返回 Date 对象的分钟 (0 ~ 59)。
      getSeconds() 返回 Date 对象的秒数 (0 ~ 59)。
      getTime() 返回 1970 年 1 月 1 日至今的毫秒数。
      Date.parse() 返回1970年1月1日午夜到指定日期(字符串)的毫秒数。
      setDate() 设置 Date 对象中月的某一天 (1 ~ 31)。
      setMonth() 设置 Date 对象中月份 (0 ~ 11)。
      setFullYear() 设置 Date 对象中的年份(四位数字)。
      toLocaleString() 年月日时分秒
      toLocaleDateString() 年月日

      var time = new Date(); //不传参 是当前时间 Thu Jan 03 2019 14:09:27 GMT+0800 (中国标准时间)

                //var time1 = new Date("2019/3/1"); //传参 代表你传的时间   转为  中国标准时间

    3、定时器

      单位:毫秒
      定时器分为:

        单次定时
          setTimeout(function(){
          console.log(1);
          },时间)
        多次定时
          setInterval(function(){
          
          },时间)
      如果想移除定时器,就要给定时器起个名字
        clearInterval(定时器的名字);
        clearTimeout(定时器的名字);

  • 相关阅读:
    使用Kubeadm创建k8s集群之节点部署(三十一)
    Jmeter之Bean shell使用(二)
    Jmeter之Bean shell使用(一)
    Jmeter之JDBC Request使用方法(oracle)
    Jmeter调试工具---HTTP Mirror Server
    Jenkins快速上手
    Jmeter之逻辑控制器(Logic Controller)
    Jmeter属性和变量
    Jmeter之HTTP Request Defaults
    Jmeter之Http Cookie Manager
  • 原文地址:https://www.cnblogs.com/ginelle/p/10215199.html
Copyright © 2011-2022 走看看