js判断时间戳是否为当天时间
var str = 1478508411000; console.log(new Date(str).toDateString()); if (new Date(str).toDateString() === new Date().toDateString()) { //今天 console.log("当天"); } else if (new Date(str) < new Date()){ //之前 console.log(new Date(str).toISOString().slice(0,10)); } 函数形式
function isToday(str) { if (new Date(str).toDateString() === new Date().toDateString()) { //今天 console.log("当天"); } else if (new Date(str) < new Date()){ //之前 console.log("以前的日期"); } } var str = 1474172800000; isToday(str);
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。