与 moment js 比较日期和时间
在我的React应用程序中,我将收到一个末日,也单独收到终结时间。我必须检查该末日和终结时间是否在当前日期和时间之前。
let endDate = "04/13/2022";
let endTime = "22:00"
console.log(moment(endDate, "MM/DD/YYYY", endTime).isBefore(moment());
//true
今天的日期与末日相同,但时间比末日早,因此我应该看到false而不是true。时间没有被比较。有人知道如何解决这个问题吗?
In my react app I am receiving an endDate, and also separately receiving an endTime. I have to check if that endDate and endTime are before the current date and time.
let endDate = "04/13/2022";
let endTime = "22:00"
console.log(moment(endDate, "MM/DD/YYYY", endTime).isBefore(moment());
//true
Today's date is the same as the endDate but the time is earlier than the endTime so I should see False instead of true. The times are not being compared. Does anyone know how to resolve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将日期和时间字符串结合在一起,并将其解析为一个全日期字符串。
Combine the date and time strings, and parse as one full date-time string.