+ Start a Discussion

GMT and Daylight Savings Time re DateTime methods, Does GMT have DST?

I always thought GMT aka UTC aka Z was absolute and never used Daylight Saving Time.  I ran the ad-hoc apex below.  I'm in Boston and we are now in Daylight Savings Time my timezone.  In my User record page, my timezone shows as "(GMT-05:00) Eastern Daylight Time (America/New_York)".  Now that seems to me to be weird is EDT is GMT-4:00 and EST is GMT-5:00 unless Salesforce considers GMT as having daylight savings time.


I ran the ad-hoc Apex below to test th difference between my time and GMT and it is indeed 5.


So, does SF move GMT to Day Light Savings time?  Does it do it on the same date as the USA moves to Daylight Savings Time?



User currentUser = [select Email,TimeZoneSidKey From User where Id=: userInfo.getUserId()];
Datetime myDateTimeLocal = DateTime.newInstance(1970,1,1);
Datetime myDateTimeGMT = DateTime.newInstanceGMT(1970,1,1);

Long myLongLocal = myDateTimeLocal.getTime();
Long myLongGMT = myDateTimeGMT.getTime();

Long hoursDiff = (myLongLocal - myLongGMT) / 60 / 60 / 1000;

System.debug ('xyzzy Diff  ' + hoursDiff);
System.debug ('xyzzy Local ' + myDateTimeLocal);
System.debug ('xyzzy GMT   ' + myDateTimeGMT);
System.debug ('xyzzy TZ    ' + currentUser.TimeZoneSidKey);



Ritesh AswaneyRitesh Aswaney

The clocks in the UK fast forward by an hour in the last week of March, whereas it happens earlier in the USA.


Could it be that the Salesforce still think its your local timezone is EST (GMT-5) rather than EDT (GMT - 4)

Ritesh AswaneyRitesh Aswaney

Or well, maybe it is applying DST to GMT for some strange reason.


I am in London, and when I execute your code, I get -1, when it should be 0, as the clocks havent been put ahead yet.


GMT is kind of an outdated term as it's someone what ambiguous whether it means British local time or the zero-meridian time that never moves, aka Z, aka UTC.


SF should really have UTC methods, not GMT methods.


Still, I not sure what I'm getting really makes sense in any case.



I disagree about the ambiguity of GMT time.  GMT stays the same year round and does not adjust for daylight savings time.  UK time is not the same time as GMT during the summer months when British Summer Time (BST) is in effect.

UTC is the same as GMT.  GMT began in the 1800's, UTC started in 1972.  Enough history lesson for one day.  :-)