获取YYYY-MM-DD当前时间function

function getDate() {
  var myDate = new Date();
  var month = myDate.getMonth() + 1;
  var Day = myDate.getDate();
  var today = "";
  if (month < 10) {
    if (Day < 10) {
      today = myDate.getFullYear() + "-0" + month + "-0" + Day;
    } else {
      today = myDate.getFullYear() + "-0" + month + "-" + Day;
    }
  }
  else {
    if (Day < 10) {
      today = myDate.getFullYear() + "-" + month + "-0" + Day;
    } else {
      today = myDate.getFullYear() + "-" + month + "-" + Day;
    }
  }
  return today
}

 

posted @ 2019-07-09 16:58  _心之所向便是光  阅读(263)  评论(0编辑  收藏  举报