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
dgindydgindy 

Formatting Time in VisualForce

I'm trying to output the Activity Time using the Outputfield.  But it's displaying 2/2/2008 10:30 AM.  The Time is right but i don't want to show the date.  Any ideas?
mtbclimbermtbclimber
Check out the format(String dateFormat) instance method on the dateTime type in Apex.


Message Edited by mtbclimber on 06-20-2008 07:05 AM
dgindydgindy
My Controller is running this

Code:
t1=[Select WhatId,Name__c,Description,ActivityDate,ActivityDateTime,Id,OwnerId from Event  where Type='In-Service'  ];
        return t1;

 
And my output is
 
Code:
<apex:sectionHeader title="Inservice" subtitle="">
      <apex:dataTable value="{!Inservice}" var="tasklist" id="theTable" rowClasses="odd,even" styleClass="tableClass" cellspacing="2" cellpadding="2">
                <apex:column width="150">
                        <apex:facet name="header" >PPC Name</apex:facet>
                        <apex:outputField value="{!tasklist.OwnerId}"/>
                </apex:column>
                <apex:column >
                        <apex:facet name="header">Name</apex:facet>
                        <apex:outputField value="{!tasklist.WhatId}"/>
                </apex:column>
                <apex:column >
                        <apex:facet name="header">Activity Date</apex:facet>
                        <apex:outputField value="{!tasklist.ActivityDate}"/>
                </apex:column>
                <apex:column >
                        <apex:facet name="header">Activity Time</apex:facet>
                        <apex:outputField value="{!tasklist.ActivityDateTime}"/>
                </apex:column>
                <apex:column >
                        <apex:facet name="header">Notes</apex:facet>
                        <apex:outputField value="{!tasklist.Description}"/>
                </apex:column>                
                
      </apex:dataTable>
      
  </apex:sectionHeader>
  

 
How do i format in the output?
jwetzlerjwetzler
As Andrew said, you need to format it in your controller.  The controller code you pasted didn't have any formatting in it.

Code:
<apex:column headerValue="Activity Time">
<apex:outputText value="{!dateTime}"/>
</apex:column>

Code:
public String getDateTime() {
Date datetime = t1.ActivityDateTime;
//do formatting here for datetime and return
}

  Also you should check out headerValue and value attributes on column.
dgindydgindy
So the only way to do formating is in the Controller.  And If I'm loading to a List<Event> I would have to run a for loop to build out an object to do so.  There must be some way to format outside the controller so that it's more dynamic
mtbclimbermtbclimber
Unfortunately there is not a way to do this in an expression today, e.g. {!FORMAT(event.activitydatetime, 'hh:mm a')}.  We are looking to add this in a future release. I recommend posting an idea to the idea exchange in the Apex & Visualforce category.