admin管理员组文章数量:1417442
When my sproc returns a null, it goes into a C# DateTime as a MinDate. If a date of this form gets to the front end (MVC/Razor), I create a "MinDate" type of my own in JavaScript for parison. If they match, I want to return an empty string from the JavaScript function. However, although the two dates match, the branch of my "if" statement that returns the empty string is never entered. I've looked at these two dates until I'm cross eyed and they appear to match. Why is my function returning the MinDate and not the empty string? (By the way, the "toString()" method is from the DateJS library.)
// Setup a minDate to mimic C#'s Date.MinDate constant.
var minDate = new Date();
minDate.setFullYear(1, 0, 1);
minDate.setHours(0, 0, 0, 0);
function checkDateWithConfig(d, c) {
alert("Date: " + d);
alert("minDate: " + minDate);
if (d == minDate) {
alert("dates matched");
return "";
}
else
{
return d.toString(c);
}
}
When my sproc returns a null, it goes into a C# DateTime as a MinDate. If a date of this form gets to the front end (MVC/Razor), I create a "MinDate" type of my own in JavaScript for parison. If they match, I want to return an empty string from the JavaScript function. However, although the two dates match, the branch of my "if" statement that returns the empty string is never entered. I've looked at these two dates until I'm cross eyed and they appear to match. Why is my function returning the MinDate and not the empty string? (By the way, the "toString()" method is from the DateJS library.)
// Setup a minDate to mimic C#'s Date.MinDate constant.
var minDate = new Date();
minDate.setFullYear(1, 0, 1);
minDate.setHours(0, 0, 0, 0);
function checkDateWithConfig(d, c) {
alert("Date: " + d);
alert("minDate: " + minDate);
if (d == minDate) {
alert("dates matched");
return "";
}
else
{
return d.toString(c);
}
}
Share
Improve this question
asked Aug 1, 2012 at 14:05
birdusbirdus
7,52417 gold badges64 silver badges95 bronze badges
1
-
Could you also please output diff of the dates
var diff = d.getTime()-minDate.getTime();
– George Mamaladze Commented Aug 1, 2012 at 14:12
1 Answer
Reset to default 6Javascript Date
objects are references.
You cannot use ==
to check whether two Date
objects represent the same value.
Instead, pare the getTime()
method on both dates, which returns a number.
本文标签: Comparing C MinDate with javascript min date failingStack Overflow
版权声明:本文标题:Comparing C# MinDate with javascript min date failing - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745264127a2650493.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论