Closed
Bug 288218
Opened 20 years ago
Closed 20 years ago
Using the JavaScript Date's setMonth(month-1) function doesn't work correctly
Categories
(Firefox :: General, defect)
Tracking
()
RESOLVED
INVALID
People
(Reporter: kenevel, Assigned: bugzilla)
Details
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6) Gecko/20050317 Firefox/1.0.2
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6) Gecko/20050317 Firefox/1.0.2
Save the following to a temporary HTML file and view in Firefox
<html>
<head>
<script type="text/javascript">
function start(){
var date = new Date();
date.setFullYear(2005);
date.setMonth(2-1);// Feb
date.setDate(5);
document.body.appendChild(document.createTextNode(date.toString()));
document.body.appendChild(document.createElement("BR"));
date.setMonth(3-1);// March
document.body.appendChild(document.createTextNode(date.toString()));
document.body.appendChild(document.createElement("BR"));
date = new Date(2005,2-1,5); // February
document.body.appendChild(document.createTextNode(date.toString()));
}
</script>
<body onload="start()">
</body>
</html>
The output is as follows:
Sat Mar 05 2005 00:19:02 GMT+0000 (GMT Standard Time)
Sat Mar 05 2005 00:19:02 GMT+0000 (GMT Standard Time)
Sat Feb 05 2005 00:00:00 GMT+0000 (GMT Standard Time)
However, line 1 is incorrect - it should be February, not March, as in the last
line.
Reproducible: Always
Steps to Reproduce:
1. No special setup steps, please see the bug details for sample JS/HTML required
Actual Results:
Please see the details section
Expected Results:
Please see the details section
Great browser, keep up the good work :)
Comment 1•20 years ago
|
||
> var date = new Date(); Wed Mar 30 2005 02:44:31 GMT+0300 (EEST) > date.setFullYear(2005); Wed Mar 30 2005 02:44:31 GMT+0300 (EEST) > date.setMonth(2-1);// Feb February 30th 2005 -> March 2nd 2005 Wed Mar 02 2005 02:44:31 GMT+0200 (EET) > date.setDate(5); Sat Mar 05 2005 02:44:31 GMT+0200 (EET) > date.setMonth(3-1);// March Sat Mar 05 2005 02:44:31 GMT+0200 (EET) > date = new Date(2005,2-1,5); // February Sat Feb 05 2005 00:00:00 GMT+0200 (EET) Looks ok.
Status: UNCONFIRMED → RESOLVED
Closed: 20 years ago
Resolution: --- → INVALID
You need to log in
before you can comment on or make changes to this bug.
Description
•