如何用 jQuery 比较两个日期值 [英] How to compare two date values with jQuery

查看:25
本文介绍了如何用 jQuery 比较两个日期值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面中有两个代表日期的字符串字段,我想比较这两个字段以了解我的第一个日期是否<第二次约会.我该怎么做?

I have two String fields which represent Dates in my page and I would like to compare these two fields to know if my first date < second date. How can I do this?

<tr>
    <td align="right">First Date: </td>
    <td align="left"> <html:text name="addPublicationForm" styleId="firstDate" property="firstDate" maxlength="10"/></td>
</tr>
<tr>
    <td align="right">Second Date: </td>
    <td align="left"> <html:text name="addPublicationForm" styleId="secondDate" property="secondDate" maxlength="10"/></td>
</tr>

推荐答案

var startDt=document.getElementById("startDateId").value;
var endDt=document.getElementById("endDateId").value;

if( (new Date(startDt).getTime() > new Date(endDt).getTime()))
{
    ----------------------------------
}

这篇关于如何用 jQuery 比较两个日期值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆