vue 显示日期只显示年月_vue获取年月日
1.暴利获取const nowDate = new Date();const date = {year: nowDate.getFullYear(),month: nowDate.getMonth() + 1,date: nowDate.getDate(),}const newmonth = date.month>10?date.month:'0'+date.monthconst day =
1.暴利获取
const nowDate = new Date();
const date = {
year: nowDate.getFullYear(),
month: nowDate.getMonth() + 1,
date: nowDate.getDate(),
}
const newmonth = date.month>10?date.month:'0'+date.month
const day = date.date>10?date.date:'0'+date.date
let systemDate = date.year + '-' + newmonth + '-' + day
alert(systemDate)
2.组件moment
npm install moment
//js引入
let moment = require('moment');
//使用
//获取当前时间
let date=new Date();
//获取当前月的第一天
let monthStart = date.setDate(1);
//获取当前月
let currentMonth=date.getMonth();
//获取到下一个月,++currentMonth表示本月+1,一元运算
let nextMonth=++currentMonth;
//获取到下个月的第一天
let nextMonthFirstDay=new Date(date.getFullYear(),nextMonth,1);
//一天时间的毫秒数
let oneDay=1000*60*60*24;
//获取当前月第一天和最后一天
let firstDay = moment(monthStart).format("YYYY-MM-DD");
//nextMonthFirstDay-oneDay表示下个月的第一天减一天时间的毫秒数就是本月的最后一天
let lastDay = moment(nextMonthFirstDay-oneDay).format("YYYY-MM-DD");
alert(monthStart)
alert(firstDay)
alert(lastDay)
更多推荐
所有评论(0)