I am trying to convert a unix time stamp to a datetime object using javascript but am getting a strange output.
The unix timestamps I'm using are 1420243200000 and 1420272000000. My javascript code looks like this:
function timeConverter(UNIX_timestamp){
// var a = new Date(UNIX_timestamp*1000);
// var year = a.getFullYear();
// var month = a.getMonth()+1;
// var date = a.getDate();
// var hour = a.getHours();
// var min = "0" + a.getMinutes();
// var sec = "0" + a.getSeconds();
// var time = date + ' ' + month + ' ' + year + ' ' + hour + ':' + min.substr(-2) + ':' + sec.substr(-2) ;
// return time;
var myDate = new Date( UNIX_timestamp *1000);
time = myDate.toLocaleString();
return time;
}
Neither the commented or uncommented attempts produce the correct date. I keep getting 9/18/46975, 6:00:00 PM and 8/17/46976, 2:00:00 AMas the answers and I can't figure out what's going wrong.