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
PabitraPabitra 

DateTime field not coming based on User Timezone in Apex. Why?

From one custom object I am retrieving one DateTime field and comparing with another dateTime field in apex. But what the Date Time field I am retrieving to apex from object, the different time showing. May be it's happening based on my user time zone.But I want this should come in apex same how it is in record.I'm not bothering about time format.But bothering about correct time value only.For matching the both time I don't want to add any hours by hard coded. Because the hard coded hours mayn't be perfect solution for all kindof time zone.Can anyone help me please?
Ravi Dutt SharmaRavi Dutt Sharma
DateTime field values are stored as Coordinated Universal Time (UTC). When a dateTime value is returned in Salesforce, it’s adjusted for the time zone specified in your org preferences. SOQL queries, however, return dateTime field values as UTC values. If you want to process these values in different time zones, your application might need to handle the conversion