我有一个带有这两个字段的JSON对象......
"start_datetime": "3/9/2016 8:00",
"stop_datetime": "3/18/2016 16:00",
如何判断当前日期/时间是否在这两者之间?
16:00 - 4 PM
08:00 - 8 AM
答案 0 :(得分:2)
可以将DateTime对象与标准比较运算符进行比较,以判断一个对象是否在另一个之前。
var start = new Date(obj.start_datetime);
var end = new Date(obj.end_datetime);
var now = new Date();
if (now > start && now < end) {
// current date and time between start and end
} else {
// current date and time not between start and end
}