如何检查具有时区的日期时间是否已在过去

时间:2016-08-25 07:09:31

标签: javascript datetime

我有这个Javascript对象数组:

[Authorize, /* with some other attributes */]
public async Task<ActionResult> ChangePassword(ChangePasswordViewModel model)
{
    // ...
    var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());
    // why they check user != null?
    if (user != null)
    {
        await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
    }
}

我想要的是检查过去是否已经var schedule = [ {"Date":"2016/08/29","Time":"02:15","GameNumber":"1","Game":"Red vs Blue"}, {"Date":"2016/09/11","Time":"02:30","GameNumber":"2","Game":"Red vs White"} ] 并在对象数组中删除它。我想用moment.js,但我不确定它是否可以。

关于如何做到这一点的任何指针或解决方案?

1 个答案:

答案 0 :(得分:2)

试试这个

schedule.forEach(function(node){
    var date = new Date(node.Date+" "+node.Time+":00"); 
    var now = new Date(); 
    if(now>date){
             console.log("Time passed");
    } 
});