My user's timezone is GMT+2 (Eastern European Time) and I notice strange thing when playing around with dates.
Date myDate = Date.newInstance(2019, 11, 29); Time myTime = Time.newInstance(9,0,0,0); System.debug(Datetime.newInstance(myDate, myTime)); System.debug(Datetime.newInstanceGmt(myDate, myTime));
I am creating Datetime instance from 9 hour. I expect Datetime.newInstance to return Datetime with 9 o'clock. And for newInstanceGmt I expect it to be 7 o'clock, because when in my timezone it's 9, in London it's 7 am.
But the result I get is the following:
09:44:51.11 (12596972)|USER_DEBUG||DEBUG|2019-11-29 07:00:00 09:44:51.11 (12638407)|USER_DEBUG||DEBUG|2019-11-29 09:00:00
It's flipped over. For some reason Salesforce is instantiating newInstance with subtracting my timezone offset, which is not logical to me.