我只想比较客户端的时间,这意味着开始时间不应该大于结束时间。我已经在网上搜索过了,但是没能解决这个问题。请尽快帮助我。提前谢谢。
发布于 2012-01-12 20:09:00
你可以在下面的代码中比较javascript中的日期
var x=new Date();
x.setFullYear(2100,0,14);
var today = new Date();
if (x>today)
{
alert("Today is before 14th January 2100");
}
else
{
alert("Today is after 14th January 2100");
}发布于 2012-01-12 20:35:35
比方说,比方说选择的时间
var startTime = "09:15";
var endTime ="10:15";
if(parseInt(startTime.split(":")[0],10) > parseInt(endTime.split(":")[0],10))
alert("Start Time should not be greater than end time");
else
alert("Valid Time");希望这能有所帮助。
发布于 2012-01-12 20:09:07
您需要使用Date对象函数来提取小时、分钟和秒,以便从日期中仅获取时间:
var currentDate = new Date();
var hours = currentDate.getHours();
var minutes = currentDate.getMinutes();
var seconds = currentDate.getSeconds();https://stackoverflow.com/questions/8834785
复制相似问题