web-utils-super
Version:
前端函数库
25 lines (21 loc) • 648 B
JavaScript
const formatTime = require('./formatTime')
/**
* @desc: 获取某天起止时间
* @param {Date | String} 年月日 '2022-2-2' | '2022/2/2' | '2022.2.2' | 不传默认是当天
* @return {Array}
*/
function getCurrentDay(time) {
const start = time ? new Date(time) : new Date()
start.setHours(0)
start.setMinutes(0)
start.setSeconds(0)
start.setMilliseconds(0)
const end = start.getTime() + 3600 * 1000 * 24 -1
// 添加至数组中返回
let startStop = new Array()
startStop.push(formatTime(start))
startStop.push(formatTime(end))
// 返回
return startStop
}
module.exports = getCurrentDay