function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Milan HrdlickaMilan Hrdlicka 

date in GMT to be converted to CET

Hello,

I have ran below code:

DateTime today = Datetime.now();
System.debug(today);

What I get is date and time in GMT and I need Centrl European Time (CET) - in other word GMT plus 1 hour.
Can anyone advise, please?

Many thanks,
Milan
Best Answer chosen by Milan Hrdlicka
Chris Gary CloudPerformerChris Gary CloudPerformer
When you run this code, it will return the Date time in the context of whatever user is running the code.  This means that is you are running the code in the 'Execute Anonymous' window of the Developer Console, it will return the GMT timezone, because the Execute Anonymous user defaults to GMT timezone.  If you know for a fact that your code will run as System user everytime (such as in a @future method) then you can simply add an hour to the DateTime variable using the addHours() method.  If your code will actually run as part of an execution invoked by a person - no worries, your code will return whatever timezone that user record is set to.

All Answers

Chris Gary CloudPerformerChris Gary CloudPerformer
When you run this code, it will return the Date time in the context of whatever user is running the code.  This means that is you are running the code in the 'Execute Anonymous' window of the Developer Console, it will return the GMT timezone, because the Execute Anonymous user defaults to GMT timezone.  If you know for a fact that your code will run as System user everytime (such as in a @future method) then you can simply add an hour to the DateTime variable using the addHours() method.  If your code will actually run as part of an execution invoked by a person - no worries, your code will return whatever timezone that user record is set to.
This was selected as the best answer
Milan HrdlickaMilan Hrdlicka
Hi Chris, many thanks for your help.
Milan