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(定时器的名字);

  • 相关阅读:
    每日总结3.8
    Go中定时器实现原理及源码解析
    Go语言实现布谷鸟过滤器
    详解Go语言调度循环源码实现
    Go语言中时间轮的实现
    详解Go语言I/O多路复用netpoller模型
    详解Go中内存分配源码实现
    Go中由WaitGroup引发对内存对齐思考
    【分享】java精品实战教程
    nginx实战教程
  • 原文地址:https://www.cnblogs.com/ginelle/p/10215199.html
Copyright © 2011-2022 走看看