封装的方法

    //判断字符串中有无某值
    $time = $_POST['time'];
    if(strpos($time,'-') === false){
        $time = $_POST['time'];
    }else{
        $time = strtotime($_POST['time']);
    }
    
    //获取随机数 $length随机数的长度
    function randomvals($length){
        $chars = '0123456789';
        mt_rand((double) microtime() * 100000 * getmypid());
        $checknode = "";
        while(strlen($checknode)<$length)
        $checknode .= substr($chars,(mt_rand()%strlen($chars)),1);
        return $checknode;
    }    

 

    location.href = location.href;
    
    //数组去重
    Array.prototype.unique = function(){
        var res = [];
        var json = {};
        for(var i = 0;i < this.length;i++){
            if(!json[this[i]]){
                res.push(this[i]);
                json[this[i]] = i;
            }
        }
        return res;
    }
    
    //数组取交集
    Array.interect = function(){
        var res = new Array();
        var obj = {};
        for(var i = 0;i<arguments.length;i++){
            for(var j=0;j<arguments.length;j++){
                var str = arguments[i][j];
                if(!obj[str]){
                    obj[str] = 1;
                }else{
                    obj[str]++;
                    if(obj[str]==arguments.length){
                        res.push(str);
                    }
                }
            }
        }
        return res;
    }
    
    //数组去并集
    Array.union = function(){
        var arr = new Array();
        var obj = {};
        for(var i=0;i<arguments.length;i++){
            for(var j=0;j<arguments.length;j++){
                var str = arguments[i][j];
                if(!obj[str]){
                    obj[str] = 1;
                    arr.push(str);
                }
            }
        }
        return arr;
    }    

function getLocalTime(nS) {
return new Date(parseInt(nS) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
}
alert(getLocalTime(1177824835));

 

 

posted @ 2017-12-27 20:25  v斌v  阅读(197)  评论(0编辑  收藏  举报