1

Would this be correct ?

function getGMT() {
    var currentTime = new Date();
    return currentTime.getTime() + currentTime.getTimezoneOffset()*60*1000;
}

in particular is it correct to add the offset or should it be subtracted ?

digitalextremist
  • 5,952
  • 3
  • 43
  • 62
kofifus
  • 17,260
  • 17
  • 99
  • 173

2 Answers2

1

Simply:

return currentTime.getTime()
Supersharp
  • 29,002
  • 9
  • 92
  • 134
0
function getGMT() {
    var currentTime = new Date();
    return currentTime.getTime() + currentTime.getTimezoneOffset()*60*1000;
    document.getElementById("wtf").innerHTML = currentTime.getHours();
}

it will spit out a number between 0-23

maybe i don't understand what you are trying to do

Peyman Mohamadpour
  • 17,954
  • 24
  • 89
  • 100
Dipz
  • 15
  • 4
  • I need the number of milliseconds since 1970/01/01 like getTime ... so you're saying adding the offset is the correct way ? – kofifus Feb 07 '16 at 02:10
  • no it is not correct to add or subtract the timezone offset. Dates are "stored" as milliseconds since 1 jan 1970 0:00:00 GMT – Jaromanda X Feb 07 '16 at 02:24