要年月日 不要时间 后端是new date 直接是当前时间
前端接收到时间后转换为Date类型,使用getFullYear(),getMonth(),getDate()处理一下。
你现在接受的数据是什么?是字符串吗?
如果想省事可以使用moment.js http://momentjs.cn/
function formatDate(dateStr) {
var newdateStr = dateStr.replace(/\d+(?=-[^-]+$)/, (a) => (parseInt(a, 10) - 1)); //字符串处理(月份)
var nums = newdateStr.match(/\d+/g); //取数
var date = eval('new Date(' + nums + ')'); //转换
//重组
var datetime =
date.getFullYear() + "-" + //年
((date.getMonth() + 1) > 9 ? (date.getMonth() + 1) : "0" + (date.getMonth() + 1)) + "-" + //月
(date.getDate() > 9 ? date.getDate() : ("0" + date.getDate())); //日
return datetime;
}