no-image

js獲取日期格式為年-月-日

                                    
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;

參考:https://www.jianshu.com/p/3415c3aa722d