programming-examples/js/Date/Write a JavaScript function to get difference to Greenwich time (GMT) in hours..js
2019-11-15 12:59:38 +01:00

10 lines
329 B
JavaScript

function diff_to_GMT(dt)
{
return (-dt.getTimezoneOffset() < 0 ? '-' : '+') + (Math.abs(dt.getTimezoneOffset() / 60) < 10 ? '0' : '') + (Math.abs(dt.getTimezoneOffset() / 60)) + '00';
}
dt = new Date();
console.log(diff_to_GMT(dt));
dt = new Date(1989, 10, 1);
console.log(diff_to_GMT(dt));