开发者

JQuery Date.parse function implementation

I am using the daterangepicker component of jquery. The Date.parse() function of jquery gives some weird output when i pass the date as "Jan 2011". Here's the sample output for different use cases:

Code snippet:

var dateStr = "Jan 2011";
var dt = Date.parse(dateStr);
alert(dt.getDate() + "/" + dt.getMonth());

Output :

dateStr = "Jan 2011"  : output = 25/0 (todays date is 25 feb 2011)
dateStr = "Feb 2011"  : output = 1/1
dateStr = "Dec 2011"  : output = 1/11

So for any other month that Jan, the date is set to 1st date of t开发者_如何学JAVAhe month, whereas only for jan the date is set to the current date.

Any idea what could be the reason for this?


It's not standart Date.parse function in you example.
Standart parse function returns numeric result, not Date object.
Javascript parse() Method

In you example parse function returns Date object.
function Date.parse was redefined in you code. Please check it.

Standart parse function always returns first day in month in your case


function myFunction() {
    var d = Date.parse("Jan 2011");
    document.getElementById("demo").innerHTML = d;
}
<!DOCTYPE html>
<html>
<body>

<p>Click the button to display milliseconds between a specified date and Jan 2011.</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

</body>
</html>

The parse() method parses a date string and returns the number of milliseconds between the date string and midnight of Jan 20111

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜