比较 JavaScript 中的时间和日期
假设有两个文本框,一个用于输入日期,另一个用于输入时间。下面是一个示例:
<p><strong>Date:</strong> <input type="text" id="datetxt"></p>
Example of how date is displayed: 25-05-1995
<p><strong>Time:</strong> <input type="text" id="timetxt"></p>
Example of how time is displayed: 14:25
有人可以建议一种在 javascript 中将文本框中的日期和时间值与当前日期和时间进行比较的方法吗,这样如果当前日期和时间超过了文本框中输入的日期和时间,那么它应该显示和警报?
Lets say there are two textboxes, one to enter in a date and the other to enter in time. Below is an example:
<p><strong>Date:</strong> <input type="text" id="datetxt"></p>
Example of how date is displayed: 25-05-1995
<p><strong>Time:</strong> <input type="text" id="timetxt"></p>
Example of how time is displayed: 14:25
Can someone suggest a way in javascript to compare values of the date and time from the textboxes to the current date and time so if the current date and time is past the date and time entered in the textboxes, then it should display and alert?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试这个
实时示例:http://jsfiddle.net/TJEMr/
Try this
Live example: http://jsfiddle.net/TJEMr/
您需要将日期字符串调整为兼容的日期格式:
工作示例:jsFiddle
You need to massage your date string into a compatible date format:
Working example: jsFiddle