I have created apex controller which is returning List<sObject> as

apex controller:


public static  List<TimeSheet__c> getDetailTimeSpendInWeek_ctrl(string selectedDate){
    string soql;
    string commaSepratedFields = 'Id, startTime__c, EndTime__c, TaskName__c, ProjectName__c, TimeDuration__c';
    string objectTypeName = 'TimeSheet__c';
    if(selectedDate == null){
        soql= 'SELECT ' + commaSepratedFields + ' FROM ' + objectTypeName + ' WHERE EntryDate__c = TODAY ';
        date pickedDate = Date.valueOf(selectedDate);
        soql= 'SELECT ' + commaSepratedFields + ' FROM ' + objectTypeName + ' WHERE EntryDate__c = :pickedDate ';
    List<TimeSheet__c> lstTimeSheet = new List<TimeSheet__c>();
    lstTimeSheet = Database.Query(soql);
    return lstTimeSheet;

component code:

<table class="slds-table slds-table--bordered slds-table--cell-buffer">
                         <aura:iteration items="{!v.weeklyReport}" var="rep">
                                   <div class="slds-truncate" >{!rep.StartTime__c}</div>
                                   <div class="slds-truncate" >{!rep.EndTime__c} </div>
                                    <div class="slds-truncate">{!rep.TaskName__c}</div>
                                    <div class="slds-truncate">{!rep.ProjectName__c}</div>
                                   <div class="slds-truncate">{!rep.TimeDuration__c} </div>

but the time starttime and end time value is coming in milliseconds , so i want to manipulate the values and convert it into HH:MM format.

please help me how can i get these values in component controller.

JS Helper:

 var action2 = component.get('c.getDetailTimeSpendInWeek_ctrl'); 
    action2.setCallback(this, function(response) {
    var state = response.getState();
    if (state == "SUCCESS") {
        var report = response.getReturnValue();



If the problem is how to present the values appropriately then try some variation of lightning:formattedDateTime in your .cmp:

<lightning:formattedDateTime value="{!rep.StartTime__c}"
        timeZone="{! $Locale.timezone }"

If you want to do some calculation in your JavaScript controller, then you can convert to a JavaScript Date object using:

var ms = ...;
var d = new Date(ms);
| improve this answer | |
  • Hi Keith, Thanks for responding on my question. i understand you points. but i am facing the problem in getting the starttime__c and endtime__c values in my JS Helper. since in helper var report = response.getReturnValue(); is returning the List<sObject> and i want to iterate that object and get the individual field as starttime__c and endtime__c. – Atul Pandey Oct 17 '18 at 7:51
  • @AtulPandey In JavaScript you can just reference the properties by name. So create a for loop and for each object just reference the field by e.g. var start = o.StartTime__c; - but note that the name is case sensitive – Keith C Oct 17 '18 at 9:58
  • Thank you Keith, i tried by the same way you told and it's working properly. – Atul Pandey Oct 18 '18 at 5:57

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.