I trying to format "ActivityDateTime" field of Events in apex and trying to display it in html table in lightning using below code:

 Event[] nextMeets = [select Id,Subject,ActivityDateTime,ActivityDate from Event where id in :eventIdSet and ActivityDate > today order by ActivityDate asc];        

    for(Event ev : nextMeets){

        String dateformat = ev.ActivityDateTime.format('yyyy-MM-dd HH:mm:ss');
        system.debug('checkdatetime' + dateformat);

         DateTime dtConverted  = Datetime.valueof(dateformat);

        System.debug('##dateInStringStringfinal - '+dtConverted);
        ev.ActivityDateTime = dtConverted;
        system.debug('checkdatefiaaalll' + ev.ActivityDateTime);

Here in the debug logs the value of the field "ActivityDateTime" is coming properly formatted like :

 ##dateInStringStringfinal - 2017-03-30 17:40:00
  checkdatefiaaalll2017-03-30 17:40:00

But when i displayed it on Html table using below code:

    <td class="slds-truncate slds-cell-wrap"> {!cell.ActivityDateTime}  </td>

its display like this : 2017-03-23T23:31:00.000Z

  • Ideally you should use a wrapper class and display data from it.
    – Raul
    Mar 11, 2017 at 9:52

1 Answer 1


This question is essentially a duplicate of: Visualforce Date formatting

That said, in this case, you should be able to put the following inside your table cell:

<apex:outputText value="{0, date, yyyy-MM-dd HH:mm:ss}">
    <apex:param value="{!cell.ActivityDateTime}" /> 

You should be able to use any supported SimpleDateFormat

  • Whats what Adrain, we cannot use any apex tag in lightning..i.e u cannot use apex:outputText here, thanks. Mar 12, 2017 at 8:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .