2

My Org is set to GMT+1 which is my timezone. (Stated in the Company Information).

I have created a record at 11:30 am but when I retrieve the CreatedDate field it says that it was created at 10:30 am. Why is the reason for that?

Thanks in advance.

EDIT:

If I do:

datetime baseTime = datetime.now();

System.debug('baseTime '+baseTime);

Integer hour = baseTime.hour();

System.debug('hour '+hour);

Integer hourGMT = baseTime.hourGmt();

System.debug('hourGMT '+hourGMT);

Then in the debug shows

enter image description here

My time is 12:39 the same as GMT+1 in the Org but the records are saved at 11:39 the same then I do datetime.now() which shows 11:39

1

All DateTime values are always saved in GMT, no matter what the user or org's time zone is set to. Further, all values are always retrieved in GMT. The user interface (e.g. Classic, Lightning) will convert those values to your selected time zone, but the API never does (it is up to the application to convert those times to local time).

If you're in GMT +1, then GMT is one hour "behind" you (or, if you will, one hour less). If you created a record at 12:39 PM your time, in your time zone, it was created at 11:39 AM in GMT. In Apex, you need to be aware of which methods work with local time, which work in GMT, and how to convert the two (see the TimeZone class).

If you want to output the values in your local time, use the format method to render the output in your time:

System.debug(System.now().format());
1

Can you check and compare your locale and user timezone? The created date field of the record you are retrieving might be adjusted to your timezone / locale.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.