zoukankan      html  css  js  c++  java
  • 数学对象和时间对象

    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( 定时器名称 );
  • 相关阅读:
    pat甲级1004 Counting Leaves
    pat甲级1003 Emergency
    pat甲级1002 A+B for Polynomials
    pat甲级1001 A+B Format
    【转载】sql注入之入门
    JavaScript基础学习笔记
    django 安装
    python web编程CGI
    python urllib库
    python数据库编程
  • 原文地址:https://www.cnblogs.com/tis100204/p/10302079.html
Copyright © 2011-2022 走看看