• 数学对象和时间对象


    1、梳理知识点
    1、数组排序 : 冒泡  选择     数组去重    
    2、数组扩展方法 : forEach    indexOf  filter   map    reduce     
    3、字符串对象 : 
        charAt   charCodeAt   String.fromCharCode
        indexOf  lastIndexOf
        substr  substring
        replace
        split
        trim  toLowerCase        toUpperCase   
     
    2、内置对象 之 数学对象 (不需要定义  直接通过Math.方法  调用方法)
    Math.pow(m,n) 计算m的n次方
    Math.sqrt(m) 计算m的平方根
    Math.abs(m) 取绝对值
    Math.max(a,b,c) 获取最大值
    Math.min(a,b,c)最小值
     
    Math.max.apply(null,[]) 计算数组的最大值
    Math.min.apply(null,[]) 计算数组的最小值
     
    三个取整方法 : 
    Math.floor( m )  向下取整  Math.floor( 3.2 )   3    Math.floor( -3.2 )  -4
    Math.ceil( m )  向上取整   Math.ceil( 3.2 )   4    Math.ceil( -3.2 )  -3
    Math.round(m) 四舍五入   Math.ceil( 3.2 )   3    Math.ceil( -3.2 )  -3
     
    Math.random() 获取0--1之间的随机小数  [0,1)
     
    获取任意区间的整数值 : 
    function rand( min,max ){
          return Math.round( Math.random()*(max-min) + min )
    }
     
    3、内置对象 之 日期时间对象  Date
    定义 :   var now = new Date(); 
     
    获取时间格式 : 
    now.getFullYear() 获取年
    getMonth()  月   0--11      使用  加+1
    getDate()   日期
    getDay()     星期  0--6   星期日--0  
    getHours()   小时
    getMinutes()  分钟 
    getSeconds()  秒
     
    4、定义一个函数  将日期转成字符串  dateToString
       function dateToString(now){
          var year = now.getFullYear();
          var month =toTwo(  now.getMonth()+1 );
          var d =toTwo(  now.getDate() );
          var h = toTwo( now.getHours() ) ;
          var m = toTwo( now.getMinutes() );
          var s = toTwo( now.getSeconds() );
          return year+"-"+month+"-"+d + " " + h + ":" + m + ":" +s;
       }
       function toTwo( str ){
          return str<10 ? "0"+str : str;
       }
     
    5、时间差
    getTime()
    封装时间差函数
       function diff(start,end){
          return (end.getTime()-start.getTime())/1000;
       }
     
    6、设置时间
    设置几天后的时间  (cookie中使用)
    setDate()   setTime()  
     
    var now = new Date();
    将now设置为3天后的时间
    now.setDate( now.getDate() + 3 )
     
    now.setTime( now.getTime() + 3*1000*24*3600 ) 换算成毫秒
     
    7、定时器
    var timer = setInterval( 要执行的任务 , 间隔时间 )   间隔时间默认是毫秒     要执行的任务一般是一个函数function(){}
    clearInterval( 定时器名称 );
  • 相关阅读:
    一个很好的国外的算法网站
    Windows 2008 R2 强制删除Cluster
    .net 4.5 新特性 async await 一般处理程序实例
    基于RSA的加密/解密示例C#代码
    解决WCF 调用方未由服务器进行身份验证或消息包含无效或过期的安全上下文令牌
    SQL Server查看所有表大小,所占空间
    关于Latch
    关闭SQL Server 数据库所有使用连接
    MysqliDb 库的一些使用简单技巧(php)
    Linux 常用命令
  • 原文地址:https://www.cnblogs.com/tis100204/p/10302079.html
Copyright © 2020-2023  润新知