I want to get the hours and minutes from a date string so I convert it to a date and then use the getHours() and getMinutes() methods. Problem is that the result is 12:20 instead of 10:20. Why does this happen and how can I get the right hour?
function myFunction() {
var d = new Date("2020-05-28T10:20:00.000Z");
hours = d.getHours();
minutes = d.getMinutes();
document.getElementById("demo").innerHTML = hours + ":" + minutes;
}
myFunction();
<div id="demo"></div>
Here you have a JSFiddle to try it:
https://jsfiddle.net/oqLsna0e/1/
Thank you!