[JavaScript] - 判断时间是否是当天

https://www.codewars.com/kata/is-the-date-today/train/javascript

function isToday(date) {
  return new Date().toDateString() === date.toDateString();
}
function isToday(date) {
  //Code goes here.
    var d = new Date(date.toString().replace(/-/g,"/"));
    var todaysDate = new Date();
    if(d.setHours(0,0,0,0) == todaysDate.setHours(0,0,0,0)){
        return true;
    } else {
        return false;
    }
}
function isToday(date) {
  return new Date().toString().substr(0, 15) === date.toString().substr(0, 15);
}
function isToday(date) {
  return date.toString().slice(0, 10) === new Date().toString().slice(0, 10);
}

 

posted @ 2019-01-25 19:47  ukyo--君君小时候  阅读(10237)  评论(0编辑  收藏  举报