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
pbergman2000pbergman2000 

Timezone problem between OutputText and OutputField

I am having a problem in a VF page that I can't seem to resolve.

 

The following code works fine and formats the output as a simple date. The problem is that the date displayed is the date in GMT and not the local date.

 

               <apex:Outputtext style=" color:black; font-size: 16pt" value="{0,date,MM/dd/yyyy a}">
                   <apex:param value="{!recordCase.CreatedDate}" />
                 </apex:outputtext>

 

 

The following code displays the date in the local time but this also shows the time of the datestamp and VF errors if I try to apply formatting as above.

 

               <apex:outputField value="{!recordCase.CreatedDate}" />

 

As near as I can tell, I need one of two solutions:

1) The ability to convert the field to local time in OutputText

2) The ability to format OutputField to only display date info

I've searched the discussion boards but haven't found anything that solves this.

 

Thanks

 

Best Answer chosen by Admin (Salesforce Developers) 
pbergman2000pbergman2000

For those of you keeping track, this is the workaround I found:

 

In the class that created the RecordCase object, I used the following:

 

        CreatedDate = formatDateTime(recordCase.CreatedDate);

 

Thus I was able to use the following in the VisualForce Page.

 

<Apex:OutputText value="{!CreatedDate}"/>

 

That gives me the local date without the time portion.

 

All Answers

Rajesh ShahRajesh Shah

Not sure about the formatting, but to display only the date, you may use Date function.

 

<apex:smileysurprised:utputField value="{!Date(recordCase.CreatedDate)}" /> 

pbergman2000pbergman2000

Thanks but that doesn't seem to work, I get an error "Syntax error Missing )" for some reason but thanks. If there is a typecast function that works, that would be helpful.

pbergman2000pbergman2000

For those of you keeping track, this is the workaround I found:

 

In the class that created the RecordCase object, I used the following:

 

        CreatedDate = formatDateTime(recordCase.CreatedDate);

 

Thus I was able to use the following in the VisualForce Page.

 

<Apex:OutputText value="{!CreatedDate}"/>

 

That gives me the local date without the time portion.

 

This was selected as the best answer