如何比较日期并检查是未来还是过去
我的日期格式为 3/13/2022 05:44 PM
。 如何将此日期与以这种方式格式化的其他日期进行比较,并检查它们是在相对过去还是未来?
I have a date formatted as 3/13/2022 05:44 PM
.
How can I compare this date with the other dates which are formatted in this manner and check whether they are in the comparative past or future?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
哦,所以你需要比较两个日期并找到最新的、过去的或未来的。
所以,你可以使用 Date.parse() 函数将日期转换为毫秒。这将解析日期字符串并返回自 1970 年 1 月 1 日午夜以来的毫秒数。
然后相应地比较这两个数字。例如:
Ohkay, so you need to compare the two dates and find which is latest, that is past or future..
So, you can just convert the dates to milliseconds using the Date.parse() function. This will parses a date string and returns the number of milliseconds since midnight January 1, 1970.
And then compare the two numbers accordingly.. For example: