我正在创建预订系统,我想确保用户不要错误地选择以前的日期。我希望以下伪代码在JavaScript中:
if(StartDateTime < Now && EndDateTime < Now)
{
alert("Bookings cannot be created for a previous date");
}
答案 0 :(得分:1)
var startDate = '5/5/2015'; // mm/dd/yyyy formate
var StartDateTime = new Date(startDate).getTime();
var endDate = '5/10/2015';
var EndDateTime = new Date(endDate).getTime();
var Now = new Date().getTime();
if(StartDateTime < Now && EndDateTime < Now){
alert("Bookings cannot be created for a previous date");
}