kingkong-utils
Version:
this is my first node utils tool
46 lines (42 loc) • 1.51 kB
JavaScript
const date = require('./src/dateFormart.js')
const escape = require('./src/htmlEscape.js')
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min; //The maximum is exclusive and the minimum is inclusive
}
function getDate() {
const date = new Date();
const year = date.getFullYear();
const month = date.getMonth() + 1;
const day = date.getDate();
const week = date.getDay();
const hour = date.getHours();
const minute = date.getMinutes();
const second = date.getSeconds();
const weekday = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
const dateStr = `${year}-${month}-${day} ${hour}:${minute}:${second} ${weekday[week]}`;
return dateStr;
}
function getDate2() {
const date = new Date();
const year = date.getFullYear();
const month = date.getMonth() + 1;
const day = date.getDate();
const week = date.getDay();
const hour = date.getHours();
const minute = date.getMinutes();
const second = date.getSeconds();
const dateStr = `${year}-${month}-${day} ${hour}:${minute}:${second}`;
return dateStr;
}
//对外暴露接口函数
module.exports = {
getRandomInt,
getDate,
getDate2,
//...require('./src/dateFormart.js'),
//三个点是展开运算符,将dateFormart.js中的内容展开到当前模块中
...date,
...escape
}