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
housingworkshousingworks 

Display Time in local time on visualforce page

I know that this is a question thats gone around a lot but I still dont have a good solution to the problem

 

I understand that date times are stores in the salesforce database as UTC, but on standard oppertunity pages the time will correctly display as the local time, but when i display the time on the visual force page it jsut shows as UTC again!!!

 

I know about the apex .format() as a way to pass the visual force page a locally formatted time, but my question is this.  If i am doing a query in my controller and returning that query back to the visual force page to be displayed into a grid, how do i get it as local time?  

 

here is my code, i simplified it here...

 

public PageReference query() {

qryString = 'SELECT Id, account.name,stageName,truck__c,pickupDateTime__c,'+ ' items_to_donate__c, drop_off_location__c,truck_size__c,neighborhood__c FROM Opportunity '+ 'WHERE CloseDate = ' + dateStr1 + ' and '+stageQuery+' ORDER BY truck__c, pickupDateTime__c ASC' ;}

}

queryResult = Database.query(qryString) ;

 

 

then on the front end i have

 

<apex:pageBlockTable value="{!queryResult}" var="a" id="rows" width="50%">

 <apex:column ><apex:facet name="header" ><b>Pickup Time</b></apex:facet>

{!a.PickupDateTime__c} </apex:column>

 </apex:pageBlockTable>

 

any help you guys can offer would be amazing!!

 

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Try using an outputField component rather than rendering the field contents directly.

 

E.g.

 

 

<apex:column > <apex:facet name="header" ><b>Pickup Time</b></apex:facet> <apex:outputField value="{!a.PickupDateTime__c}" /> </apex:column>

 

 

 

 

All Answers

bob_buzzardbob_buzzard

Try using an outputField component rather than rendering the field contents directly.

 

E.g.

 

 

<apex:column > <apex:facet name="header" ><b>Pickup Time</b></apex:facet> <apex:outputField value="{!a.PickupDateTime__c}" /> </apex:column>

 

 

 

 

This was selected as the best answer
KnewTVsKnewTVs

This worked for me and keeps it simple. 

 

Thanks

KCWKCW

Thanks for the post,

 

That took care of it.