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,932
  • 3
  • 41
  • 61
kofifus
  • 14,411
  • 12
  • 82
  • 140
  • 1
    Possible duplicate of [How do I get a UTC Timestamp in JavaScript?](http://stackoverflow.com/questions/9756120/how-do-i-get-a-utc-timestamp-in-javascript) – Pmpr.ir Feb 07 '16 at 02:04
  • not duplicate, I'm after GMT not UTC – kofifus Feb 07 '16 at 02:05
  • 3
    Actually, GMT is UTC. – Tserkov Feb 07 '16 at 02:06
  • GMT is a time zone and UTC is a time standard (http://www.timeanddate.com/time/gmt-utc-time.html) ... Sorry I cannot understand from the other question how to get GMT as integer without accessing a remote server. – kofifus Feb 07 '16 at 02:07
  • 1
    `is it correct to add the offset or should it be subtracted` - neither – Jaromanda X Feb 07 '16 at 02:18

2 Answers2

1

Simply:

return currentTime.getTime()
Supersharp
  • 26,125
  • 8
  • 76
  • 119
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

Pmpr.ir
  • 16,260
  • 23
  • 83
  • 97
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