I have a problem which can’t solve by myself.
Here is timestamp 1308085200 taken from my website database. It represents 2011-06-15 12:00:00
Here is javascript code which I use to “fetch” date in human readable format.
var date = new Date(1308085200 * 1000);
var year = date.getFullYear();
var month = date.getMonth();
var day = date.getDate();
var hour = date.getUTCHours();
var minute = date.getUTCMinutes();
var seconds = date.getUTCSeconds();
The problem is that I get wrong results. For example the code above shows 2011-5-15 21:0:0 instead of 2011-06-15 12:00:00
What I do wrong and how to fix that ?
JavaScript’s
Date::getMonth()returns a zero-based integer from 0 to 11 which is why your date is showing May instead of June.https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/getMonth
Update
As for the time portion, this is what I get (AEST)
Looks like your timestamp is actually not what you think it is.