How can we set timezone for “Date” Field should be set to 'Australia/Melbourne'

1.6K    Asked by DelbertRauch in Salesforce , Asked on Aug 5, 2021

I need help from experts for a lightning data table with 'Date' type field. I want to strictly set it's timezone to 'Australia/Melbourne' irrespective of user's local timezone. For example, Even if an user from India is checking the record, the 'Date' field should display data in 'Australia/Melbourne' timezone only. How can i set australia date and time in lightning data table.

I am using the below code, but it is not working :

const columns = [ { fieldName: "Date", hideDefaultActions: true, label: "DATE", type: "Date", sortable: "true", typeAttributes: { timezone: 'Australia/Melbourne' } } ]

Let me know if any further inputs needed from my end. Thanks!


Answered by Ian Robertson

You're using the date local value when you should be using the date value. It uses the lightning-formatted-date-time component so you have to follow the spec for this component. Just to be explicit here it is straight from the docs: date-local Displays a date that is formatted based on the locale using lightning-formatted-date-time. To include a time value, use the date type instead. The value passed is assumed to be in the browser local time zone and there is no time zone transformation.

 Or you can try timeZoneName attribute For setting Australia date and time.



Your Answer

Interviews

Parent Categories