+ Start a Discussion
Mitchell McLaughlin 10Mitchell McLaughlin 10 

Get Current Time in Lightning Component

Hello All,

I'm trying to get EST current time oninit whenever my lightning component is opened. I have concerns about pulling the time in the user's timezone as they are not necessarily in eastern. I also have concerns about pulling the general time of GMT which is used in SFDC development because of daylight savings.

Basically, I want to always dynamically hide a component if it is before 8:30 in the morning. 

Please help! Thanks.
Anant KamatAnant Kamat
Hi Mitchell,
Kindly refer the below 2 links. Hope these are helpful to you

Deepali KulshresthaDeepali Kulshrestha
Hi Mitchell,

Follow below code, it will help you to show date in lightning component

   <aura:handler name="init" action="{!c.init}" value="{!this}" />
   <aura:attribute name="today" type="Date" />
   <ui:outputDate value="{!v.today}" />

init : function(component, event, helper) {
    var today = $A.localizationService.formatDate(new Date(), "YYYY-MM-DD");
    component.set('v.today', today);

I suggest to visit these links,it will help you




I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha.