js根据当前日期并展示为2018-08-13格式
1、js获取当前日期
var date = new Date();
var seperator1 = "-";

2、js获取当前日期 的年月日
var year = date.getFullYear();
var month = date.getMonth() + 1;
var strDate = date.getDate();

3、js将获得的年月日进行字符串拼接
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var currentdate = year + seperator1 + month + seperator1 + strDate;

4、完整代码
//获取当前日期2018-08-13
function getNowFormatDate() {
var date = new Date();
var seperator1 = "-";
var year = date.getFullYear();
var month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var currentdate = year + seperator1 + month + seperator1 + strDate;
return currentdate;
}
js中直接引用
var today = getNowFormatDate();
此时today ='2018-08-13'
