|Unix timestamp TO date with offset|
| 11:36 am on Apr 13, 2012 (gmt 0)|
Hello All -
Brain-wracking issue here.
That is, it's perfect for users in my timezone (Manila, Philippines).
var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
var stamp = 1335024000;
var a = new Date(stamp*1000);
var date = a.getDate();
var month = months[a.getMonth()];
I've investigated getTimezoneOffset() and, it does give a -5 hour offset from UTC, but I don't understand how to alter my code to accommodate this offset.
Will getTimezoneOffset() correct this issue? If not, how does one deal with this issue?
All guidance greatly appreciated.
alert(date + ' ' + month);
| 1:56 pm on Apr 13, 2012 (gmt 0)|
Lets calculate the difference.
var jan_1_1970 = new Date(1970, // year
0, // month
1, // day
0, // hour
0, // minute
0, // second
0); // millisecond
var apr_22_2012 = new Date(2012,
var difference = apr_22_2012.getTime() - jan_1_1970.getTime();
// difference = 1335049200000 != 1335024000000
In other words, your stamp value is incorrect. It is off by 7 hours.
1335049200000 - 1335024000000 = 25200000 ms
25200000ms / 1000 = 25200 seconds
25200 s / 60 = 420 minutes
420 m / 60 = 7 hours
| 1:54 am on Apr 16, 2012 (gmt 0)|
Thanks very much for your reply.
That's very unusual as the time stamp I'm using always keeps coming up with the same result as I had posted initially UNLESS I change the php timezone ini setting. This is something I'm going to have to investigate further on the php forum.
At any rate, I have found a work-around which yields the correct date display no matter what timezone the users system clock is set to.
Thanks again for your guidance.