-1

I am finding it hard to keep Timezone same for end user as specified in Salesforce Company Information. Here are some details

  1. Orgs Time Zone (GMT-07:00) Pacific Daylight Time (America/Los_Angeles).
  2. Users/Browsers timezone (GMT +05:30)

Now, I am using a custom field that stores DateTime. Lets suppose we have stored March 11, 2AM in it. When parsing the field in LWC it displays, ***March 11, 14:30 ***, Here is conversion I am using.

let dt = new Date(record.Start_Date__c);

I am aware of @salesforce/i18n/internationalizationProperty but it is again limited to userlocale. I want date time to be same on every browser.

1 Answer 1

2

Times are always stored and retrieved in GMT, regardless of the org's "default time zone" setting. If you're in an environment that supports lightning-input type="datetime" and lightning-formatted-date-time, you can provide the value directly into these components without using new Date(...), and providing a timezone property, and these components will automatically render the correct input/output value in the desired time zone.

If you need for some other purpose, you can use the original date time string, replace the Z in it with the desired time zone offset, and it should calculate:

let dt = new Date(record.Start_Date__c.replace('Z').('-07:00'));

However, again, if you're using the standard components, do not do this, as they expect the input to already be GMT+00:00, so you don't need to manually convert the time, just specify the timezone.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .