[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);
}

 

转载于:https://www.cnblogs.com/ukzq/p/10321377.html

    原文作者:weixin_34344677
    原文地址: https://blog.csdn.net/weixin_34344677/article/details/94662144
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞