const currentDate = new Date();
const year = currentDate.getFullYear();
const month = String(currentDate.getMonth() + 1).padStart(2, '0');
const day = String(currentDate.getDate()).padStart(2, '0');
return `${year}-${month}-${day}`;
* 获取当前时间 格式 hh:mm:ss
getCurTime() {
const now = new Date();
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
const seconds = String(now.getSeconds()).padStart(2, '0');
return `${hours}:${minutes}:${seconds}`;
let dateUtils = new DateUtils()
export default dateUtils as DateUtils
使用时直接导入即可:
import DateUtils from "../../common/utils/DateUtils"
let sendDate = DateUtils.getCurDate()
let sendTime = DateUtils.getCurTime()