this.D = new Date(1433760825 * 1000);
this.NewD = this.D.getHours();
D = "2015-06-08T10:53:45.000Z" - this is fine, it is what I was expecting to get. But...but....NewD results to 11 and Not 10. Why???
Thanks!
this.D = new Date(1433760825 * 1000);
this.NewD = this.D.getHours();
D = "2015-06-08T10:53:45.000Z" - this is fine, it is what I was expecting to get. But...but....NewD results to 11 and Not 10. Why???
Thanks!
When you instantiate the Date object using a value like this, you get a date based on UTC. From MDN:
Integer value representing the number of milliseconds since 1 January 1970 00:00:00 UTC (Unix Epoch).
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
When you subsequently call the getHours() method, you get the hours in your local time zone.
So for your example:
var sampleDate = new Date(1433760825 * 1000);
var hours = sampleDate.getUTCHours();
alert(sampleDate);
alert(this.hours);
Should get you the result you are looking for.
A couple of quick points:
Don't use single character variable names, and don't capitalize them if you do
D is not equal to the date that you put in.
The new Date(value) is expecting an integer and you are giving it something larger then an integer. So it is defaulting back to current time.
Try using a DateString, or other method as described in this documentation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
When you create a DateObject, if you try to print it, it will print the datetime according to UTC. But when you do the getHours() property it will tell you the hours passed according to your own local time zone.
(new DateTime()).getHours()
This will return the hours in (UTC + offset) according to your timezone.