2 回答
TA贡献1789条经验 获得超8个赞
您可以使用options参数.toLocaleString将日期格式设置为“MM/DD/YYYY”
var currentDate = new Date(Date.now() + (8 * 86400000))
var newDateOptions = {
year: "numeric",
month: "2-digit",
day: "2-digit"
}
var newDate = currentDate.toLocaleString("en-US", newDateOptions );
console.log(newDate)
有关如何使用参数的详细帖子.toLocaleString- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString
TA贡献1765条经验 获得超5个赞
var currentD = new Date();
var startHappyHourD = new Date();
startHappyHourD.setHours(17,30,0); // 5.30 pm
var endHappyHourD = new Date();
endHappyHourD.setHours(18,30,0); // 6.30 pm
console.log("happy hour?")
if(currentD >= startHappyHourD && currentD < endHappyHourD ){
console.log("yes!");
}else{
console.log("no, sorry! between 5.30pm and 6.30pm");
}
添加回答
举报