JavaScript日期格式问题 [英] JavaScript Date Format Problem

查看:96
本文介绍了JavaScript日期格式问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码

This is My Code

var txtFromDate = document.getElementById("<%=txtFromDate.ClientID%>").value;
var txtToDate = document.getElementById("<%=txtToDate.ClientID%>").value;

var D1 = new Date(txtFromDate);
var D2 = new Date(txtToDate);

if(D1 > D2)
   alert("FromDate cannot be greater than ToDate");


但是这里的问题是
-> txtFromDate和txtToDate采用"dd-mmm-yyyy"日期格式(2011年1月22日)
->这就是为什么D1和D2都以"NaN"的形式出现的原因
->我不能做的Bcoz比较bw D1& D2

->给我一个解决方案,这样我就可以将22-Jan-2011格式转换为22-01-2011
->否则,关于日期比较bw D1&的任何其他解决方案. D2

谢谢...


But Problem here is
--> txtFromDate and txtToDate are in "dd-mmm-yyyy" Date Formate (22-Jan-2011)
--> Thats why D1 and D2 vale coming as "NaN"
--> Bcoz of this I cant do comparison bw D1 & D2

--> Give me a solution so that i can convert 22-Jan-2011 format to 22-01-2011
--> Or else any other solution with respect with Date Comparison bw D1 & D2

Thank You...

推荐答案

您好,

试试这个

Hello,

try this

if (Convert.ToDateTime(txtIn.Text) > Convert.ToDateTime("1/1/2000"))
            {
                lblOut.Text = "greater then 1/1/2000";
            }
            else
            {
                lblOut.Text = "equal or less then 1/1/2000";
            }


这对我有用

sanjeev


this works for me

sanjeev


我相信您真正的问题是格式.
此处是有关javascript中日期格式的一些不错的工作.他们提供了一个 javascript库,它可能会有所帮助.

如果您可以使用JQuery插件,这里是一个,我认为这会有所帮助.

希望对您有所帮助!
I believe your real issue is the format.
Here is some nice work done on Date formatting in javascript. They provide a javascript library which might be of some help.

If you can use JQuery plugins, here is one which I think will be helpful.

Hope this helps!


更改日期格式
Change the date format
var txtFromDate = ''23/Jan/2011'';//document.getElementById("<%=txtFromDate.ClientID%>").value;
var txtToDate = ''22/Jan/2011'';//document.getElementById("<%=txtToDate.ClientID%>").value;

var D1 = new Date(txtFromDate);
var D2 = new Date(txtToDate);
if(D1 > D2)
{
    alert("FromDate cannot be greater than ToDate");
}
else
{
  //Nothing

}


这篇关于JavaScript日期格式问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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