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
liwuliwu 

inputField DateTime format

One of the columns in my apex:dataTable is displaying a DateTime field. I do this like so:

 

<apex:column >
  <apex:facet name="header">Date</apex:facet>
  <apex:outputText value="{0,date,yyyy-MM-dd HH:mm:ss}">
    <apex:param value="{!MyObj.MyDate__c}" />
  </apex:outputText>      
</apex:column>

 The problem I have is that this date is being displayed in GMT and not the timezone of my login (BST). Is there a way to adjust this? 

 

On a sidenote, if I use this same MyObj.MyDate__c field in an apex class and do something like:

 

MyObj.MyDate__c.format('yyyy-MM-dd HH:mm:ss')

 It does format into my own timezone (BST)

 

 

izayizay

You can use a wrapper class in your controller to hold each record and the formatted date.

 

Controller:

 

public class my controller{

   

    public class myObjectWrapper{

        public String formatDate{get; set;}

        public MyObject__c obj{get; set;}

        public myObjectWrapper(MyObject__c obj){

            this.obj = obj;

            formatDate = obj.MyDate__c.format(yyyy-MM-dd HH:mm:ss);

        }

    }

 

}

 

Page:

 

<apex:column >
  <apex:facet name="header">Date</apex:facet>
  <apex:outputText value="{!obj.formatDate}">
  </apex:outputText>     
</apex:column>