js get date format as year-month-day

var date = new Date();
var nowMonth = date.getMonth() + 1;
var strDate = date.getDate();
var seperator = "-";
if (nowMonth >= 1 && nowMonth <= 9) {
  nowMonth = "0" + nowMonth;
}
if (strDate >= 0 && strDate <= 9) {
  strDate = "0" + strDate;
}
var nowDate = date.getFullYear() + seperator + nowMonth + seperator + strDate;

Reference: https://www.jianshu.com/p/3415c3aa722d

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325042025&siteId=291194637
Recommended