时间戳转换为日期

timestampToTime(timestamp) {
var date = new Date(timestamp);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
let Y = date.getFullYear() + ‘-‘;
let M = (date.getMonth()+1 < 10 ? ‘0’+(date.getMonth()+1) : date.getMonth()+1) + ‘-‘;
let D = (date.getDate() < 10 ? ‘0’+date.getDate(): date.getDate()) + ‘ ‘;
let h = (date.getHours() < 10 ? ‘0’+date.getHours(): date.getHours()) + ‘:’;
let m = (date.getMinutes() < 10 ? ‘0’+date.getMinutes(): date.getMinutes()) + ‘:’;
let s = (date.getSeconds() < 10 ? ‘0’+date.getSeconds(): date.getSeconds());
return Y+M+D+h+m+s;
},


大数相加:

function largeNumAdd(num1, num2) {
let maxLength = Math.max(num1.length, num2.length);
//num1和num2位数对齐,位数较小的前面补0
num1 = num1.padStart(maxLength, ‘0’);
num2 = num2.padStart(maxLength, ‘0’);
let res = ‘’;//存放最后得到的结果
let figure = 0;//figure = 两个数字对应位数数值相加 + 进位
let currentNum = 0;//对应位数的结果
let carry = 0;//进位
for(let i=num1.length-1; i>=0; i–) {
figure = parseInt(num1[i]) + parseInt(num2[i]) + carry;
currentNum = figure % 10;
carry = Math.floor(figure / 10);
res = currentNum + res;
}
return res
}


百度站长平台推送:

const http = require(‘http’)
// 要推送的链接,以数组方式
let pushList = []
var path = ‘/urls?site= &token= ‘ //携带站点链接以及秘钥
// 配置好百度站长平台的推送链接
for(var i = 0; i < pushList.length; i++) {
// console.log(pushList[i].length);
let params = {
host: “data.zz.baidu.com”,
path: path,
method: “post”,
“User-Agent”: “curl/7.12.1”,
headers: {
“Content-Type”: “text/plain”,
“Content-Length”: pushList[i].length
}
};
let httpReq = http.request(params, function(res) {
res.setEncoding(“utf8”);
res.on(“data”, function(data) {
console.log(“data:”, data);
});
});
httpReq.write(pushList[i]);
httpReq.end();
}


快速排序js版

function quickSort(arr){
if(arr.length<=1){ return arr}
var baseIndex = Math.floor(arr.length / 2) ; //基准的下标
var baseValue = arr.splice(baseIndex, 1)[0]; // 把基准从数组分离出来
var left = []; // 基准左边子集存放变量
var right = []; // 基准右边子集存放变量
for(var i=0;i<arr.length;i++){
if(arr[i]<= baseValue){
left.push(arr[i])
}else{
right.push(arr[i])
}
}
return quickSort(left).concat([baseValue],quickSort(right))
}