40

I have a calendar built in JavaScript that compares dates with PHP. The JavaScript date object is set using PHP, but, when I compare future dates, they appear to be out of sync.

PHP is set to GMT and JavaScript is set to UTC; how do these standards differ, and could this be causing the problem?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Tom
  • 1,651
  • 3
  • 19
  • 19
  • 10
    For practical purposes (and certainly all cases a computer will see), GMT is UTC. Your timezone problem lies elsewhere. Let's see some code. – bobince Oct 23 '09 at 12:02

4 Answers4

37

From Coordinated Universal Time on Wikipedia:

Coordinated Universal Time (UTC) is a time standard based on International Atomic Time (TAI) with leap seconds added at irregular intervals to compensate for the Earth's slowing rotation.

From Greenwich Mean Time on Wikipedia:

UTC is an atomic time scale which only approximates GMT with a tolerance of 0.9 second

  • 24
    Which, for pretty much any application should be something you can ignore. Exceptions are very rare and those exceptions are very unlikely to be written in PHP anyway. – Joey Oct 23 '09 at 08:52
  • That should be UT1 not GMT. – orome Dec 15 '14 at 17:34
  • Even more importantly: "[UTC] is one of several closely related successors to Greenwich Mean Time (GMT). For most purposes, UTC is considered interchangeable with GMT, but GMT is no longer precisely defined by the scientific community" – Ciro Santilli OurBigBook.com Dec 05 '15 at 16:14
34

One is measured from the sun and another from an atomic clock.

For your purposes, they are the same.

aug
  • 11,138
  • 9
  • 72
  • 93
Ben James
  • 121,135
  • 26
  • 193
  • 155
1

For computers, GMT is UTC+0 - so they are the equivalent.

Jasen
  • 11,837
  • 2
  • 30
  • 48
0

If you strictly go by the definition of what UTC and GMT are, there is no real practical difference as others have pointed out.

However one needs to be careful as there are certain cases where (possibly legacy) terminology is used such as in the Microsoft Timezone index values

The difference is that in that context, what is referred to as the "GMT timezone" (code 55) is, in reality, the "GMT locale" which is the locale used by Dublin, Edinburgh, Lisbon, London (all of which observe daylight savings time) which is differentiated from Greenwich Standard Time (code 5A) which is used by Monrovia and Reykjavik both of which do not observe daylight savings time.

The practical difference is that if a system is set up to use UTC (code 80000050 under the semantics specified above) then it will not automatically switch to daylight savings time while if you set your time zone to GMT (code 55) then there's a good chance it automatically switches to BST during the summer without you noticing.

apokryfos
  • 38,771
  • 9
  • 70
  • 114
  • if you set it to "GMT" is should stay there. if you set it to "London" it should follow the civil time rules of that locale switching to BST in the summer – Jasen Sep 21 '17 at 03:07
  • @Jasen as far as I know London is not a timezone but a locale. You can set a server to the London locale but the server will then report GMT as its timezone half the year and BST for the other half. However if you don't set a locale then it will just report UTC all year round. If you're using Windows then the London locale is confusingly called GMT or BST or something ambiguous for some reason. It's just a whole can of worms you really don't want to be opening. – apokryfos Sep 21 '17 at 06:36
  • Totally agree WRT windows. – Jasen Sep 28 '17 at 10:27
  • **Incorrect.** Do not conflate UTC/GMT with [London time](https://en.wikipedia.org/wiki/Time_in_the_United_Kingdom). London time observes Daylight Saving Time (DST). UTC and GMT by definition do not. UTC/GMT is the base against which all other zones and DST are measured by an offset of some number of hours-minutes-seconds ahead or behind. For half the year when London is not on DST, its wall-clock time happens to coincide with UTC/GMT. The geographical location of the UTC/GMT longitude happens to run through London (Greenwich) but conceptually that is irrelevant. – Basil Bourque Nov 16 '18 at 20:46
  • @BasilBourque the confusion sometimes lies when one reads the microsoft time zones like e.g. https://support.microsoft.com/en-gb/help/973627/microsoft-time-zone-index-values where the London timezone is named GMT standard time and there's a different code for UTC. Digging deeper you can find that this is because what they call "GMT" is actually "Londong time" which can be either GMT or BST. – apokryfos Nov 17 '18 at 09:28
  • @apokryfos Seems like you may have a valid point. So rewrite your Answer to say *that*. Then I’ll retract my comment and down-vote. – Basil Bourque Nov 17 '18 at 14:33
  • @BasilBourque Thanks for the note. I've clarified my point, it hopefully is more clear now. – apokryfos Dec 10 '18 at 10:59