function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RarLopzRarLopz 

When I get a response from the webservice, how can i display the time I get the response on lightning component

i am trying to display the time from Apex controller to Lightning component. 
is it possible to directly get Datetime.now () in the js controller and display it on the component? 



({	
	ctr : function(cmp, event, helper) {
        var temp = [];
       
        var action = cmp.get("c.getGraph");
        action.setParams({
        	"accountid": cmp.get("v.recordId")
       	});
        action.setCallback(this, function(response){
            if(response.getState() === 'SUCCESS' && response.getReturnValue()){
                temp = response.getReturnValue();
                helper.createGraph(cmp, temp);
            }
        });      
          
       $A.enqueueAction(action);
      
	},
    
    cancelAction: function(component, event, helper) {
   		$A.get("e.force:closeQuickAction").fire();
	}
})



 
Best Answer chosen by RarLopz
Deepali KulshresthaDeepali Kulshrestha
Hi RarLopz
Greetings to you!

I have added a field in the temp variable as the dateTime field. you can display this dateTime any where on your component by storing temp variable in an aura attribute variable.
if yoy have datetime value in the response then you can use aura component formatted date time to display it.
https://developer.salesforce.com/docs/component-library/bundle/lightning:formattedDateTime/example
 
({    
    ctr : function(cmp, event, helper) {
        var temp = [];
        
        var action = cmp.get("c.getGraph");
        action.setParams({
            "accountid": cmp.get("v.recordId")
        });
        action.setCallback(this, function(response){
            if(response.getState() === 'SUCCESS' && response.getReturnValue()){
                temp = response.getReturnValue();
                var today = new Date();
                var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
                var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
                var dateTime = date+' '+time;
                console.log('datetime--->'+dateTime);
                temp.dateTime = dateTime;      
                helper.createGraph(cmp, temp);
            }
        });      
        
        $A.enqueueAction(action);
        
    },
    
    cancelAction: function(component, event, helper) {
        $A.get("e.force:closeQuickAction").fire();
    }
})
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

All Answers

Deepali KulshresthaDeepali Kulshrestha
Hi RarLopz
Greetings to you!

I have added a field in the temp variable as the dateTime field. you can display this dateTime any where on your component by storing temp variable in an aura attribute variable.
if yoy have datetime value in the response then you can use aura component formatted date time to display it.
https://developer.salesforce.com/docs/component-library/bundle/lightning:formattedDateTime/example
 
({    
    ctr : function(cmp, event, helper) {
        var temp = [];
        
        var action = cmp.get("c.getGraph");
        action.setParams({
            "accountid": cmp.get("v.recordId")
        });
        action.setCallback(this, function(response){
            if(response.getState() === 'SUCCESS' && response.getReturnValue()){
                temp = response.getReturnValue();
                var today = new Date();
                var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
                var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
                var dateTime = date+' '+time;
                console.log('datetime--->'+dateTime);
                temp.dateTime = dateTime;      
                helper.createGraph(cmp, temp);
            }
        });      
        
        $A.enqueueAction(action);
        
    },
    
    cancelAction: function(component, event, helper) {
        $A.get("e.force:closeQuickAction").fire();
    }
})
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
This was selected as the best answer
RarLopzRarLopz
@Deepali Kulshrestha, sorry for the delayed response. Thankyou for the suggestion. Much appreciated as always!!