0

I have 2 datetimes with fixed values: 2020-09-12T18:13:41Z

  <lightning:input aura:id="stst" type="datetime" name="input3" label="{!$Label.c.Start_Date_Time}" required="true" value="2020-09-12T18:13:41Z" class="slds-size--1-of-2 slds-p-horizontal_x-small"/>
  <ui:inputDateTime aura:id="expdate" label="Expense Date" class="form-control" value="2020-09-12T18:13:41Z" displayDatePicker="true" />

but my UI its showing that its 20 PM Why?

enter image description here

thanks!

Edited:

I cant adjust because when I save the record the correct value "18" is displayed. Also have multiple timezones, more than 4 countries

enter image description here

enter image description here

SOLUTION: To set your Datetime you need to set it with UTC

for example if your GMT is GMT+3 and the current time its 18:00

you have to set: 15:00

your component its gonna display 18:00

but the value that its gonna be save will be 15:00 with a final Z that means UTC

4

It looks like you're in GMT+02:00. The time you specified is in GMT+00:00 (that's what the "Z" in the time string represents). The UI automatically translates the time to your local time zone, so it ends up being 20 instead.

2
  • if I remove the Z the dateime its not displayed, how can I specify a timezone? – Tomas Garcia Etchegaray Apr 1 '20 at 9:00
  • @TomasGarciaEtchegaray There's a separate attribute you can set, timezone, that allows you to specify a timezone to use for input/output. – sfdcfox Apr 1 '20 at 12:17
0

Salesforce stores datetime as UTC/GMT. It will automatically convert the offset depending on your local time zone so if you look at your time zone setting of your org you can do the difference and adjust your hard coded value accordingly.

In this case, you want 16 instead of 18.

1
  • I cant adjust because when I save the record the correct value "18" is displayed – Tomas Garcia Etchegaray Apr 1 '20 at 7:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.