0

Today I noticed one awkward behavior of **<lightning:formattedDateTime>** aura component.

Examples:

I have a component where I need to display today date like Nov 5, 2019

But when i use **<lightning:formattedDateTime>** its display the 1 Day behind Nov 4, 2019

and when i use **<ui:outputDate>** Its showing perfect date Nov 5, 2019

This happens only when I'm in the US timezone only.

Is it anybody face this type of issue or its a bug in ?

  • 1
    Did you have a look at the "timezone" attribute of lightning:formattedDateTime? – Florian Heer Nov 5 '19 at 22:54
0

This is because ui:outputDate shows time in UTC, but lightning:formattedDateTime shows time based on runtime environment's time zone which will be different based on location. If you want this to be specific time zone then you can set that using timeZone attribute of lightning:formattedDateTime.

The time zone to display. Use this attribute only if you want to override the default, which is the runtime environment's time zone. Specify a time zone listed in the IANA time zone database (https://www.iana.org/time-zones). For example, set the value to 'Pacific/Honolulu' to display Hawaii time. The short code UTC is also accepted.

This is how you can specify time zone.

<lightning:formattedDateTime value="1547250828000" timeZone="UTC" />

Which will show you an exact time as in ui:outputDate.

If you want American time zone then below code should work for you.

<lightning:formattedDateTime value="1547250828000" year="numeric" month="numeric" day="numeric"  hour="2-digit" minute="2-digit" timeZoneName="short" timeZone="America/New_York" />

Please note that ui:outputDate is Deprecated as of API version 47.0. Use lightning:formattedDateTime instead.

Please refer for more details.

lightning:formattedDateTime

ui:outputDate

| improve this answer | |

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.