Reputation: 613
I'm working with dates using javascript, and have come across a odd problem
function updateRow(element){
var data = element.name.match(/stamp\[(\d+)\]\[(\d+)\]/);
if(data[2] == 3){
var raw = element.value.match(/(\d+):(\d+):(\d+)/);
var time = 0;//((raw[1] * 3600) + (raw[2] * 60) + (raw[3] * 1)) * 1000;
//Hardcoded just to test
var test = new Date("2015-02-18 13:16:06");
var date = new Date(test.getTime());
document.getElementById(data[1]+"-2").value =
date.getFullYear()+"-"+
fillZero(date.getMonth(), 2)+"-"+
fillZero(date.getDay(), 2)+" "+
fillZero(date.getHours(), 2)+":"+
fillZero(date.getMinutes(),2)+":"+
fillZero(date.getSeconds(),2);
}
}
The date I get from should be the 2015-02-18 13:16:06, but from some odd reason I get 2015-01-03 13:16:06, but I have no idea why.
Upvotes: 0
Views: 72
Reputation: 1055
Use date.getDate() instead of date.getDay() and add +1 in getMonth
Upvotes: 2