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
GirinoobGirinoob 

How to store EST time in Date/Time field

Hello,

I have a Date/Time field in my object. I want to store the time in EST format through apex code. How to do it ? is it possible ?

At present the time is getting stored in GMT format.

 

Thank you!

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

Date/Time values are always stored in GMT if stored in a DateTime field. The system automatically converts those times to the user's local time zone when viewed in the UI. To specifically store a time as a given offset, you would need to store the value as a text value in a normal text field. You will need to figure out a way to determine the necessary offset (keeping in mind DST will be ignored, so you'll have to determine a way to calculate if DST has caused an hour time difference). In general, you should avoid trying to defeat the time zone calculations, because it is contrariwise to the rest of the UI, which always calculates the correct local time for the user. If a user wishes to use dates and times in EST, they should instead simply adjust their user's time zone settings. Perhaps a better use of your time would be to create a sidebar "change time zone" widget so users can quickly change their current time zone.