📌  相关文章
📜  获取当前日期 javascript yyyy-mm-dd - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:11.043000             🧑  作者: Mango

代码示例6
function pad2(n) {
  return (n < 10 ? '0' : '') + n;
}

var date = new Date();
var month = pad2(date.getMonth()+1);//months (0-11)
var day = pad2(date.getDate());//day (1-31)
var year= date.getFullYear();

var formattedDate =  year+"-"+month+"-"+day;
alert(formattedDate); //2021-02-28