How to show DateTime in Visualforce page in User’s Time Zone instead of GMT in Salesforce?

How to show DateTime in Visualforce page in User’s Time Zone instead of GMT in Salesforce?

Sample Code:

<apex:page StandardController="Opportunity">  
  
    GMT:   
    <apex:outputText value=" {0,date,M/d/yyy h:mm a}">  
        <apex:param value="{!Opportunity.LastModifiedDate}"/>  
    </apex:outputText>  
    <br/>  
    User Time Zone:   
    <apex:outputField value="{!Opportunity.LastModifiedDate}"/>  
      
</apex:page>  

Output:

For using apex:outputText tag use

<apex:page>  
      
    <table>  
        <tr>  
            <td><apex:outputText value="User Local Time Zone time is: {! NOW() }" /></td>  
        </tr>  
        <tr>  
            <td><apex:outputText value="GMT Time Zone time is: {0,date,yyyy.MM.dd G 'at' HH:mm:ss z}"><apex:param value="{! NOW() }" /></apex:outputText></td>  
        </tr>  
    </table>  
  
</apex:page>

Note:
<apex:outputText value=”{!NOW()}” />  – it will show GMT time.
<apex:outputText value=” {!NOW()}” /> – it will show time in your local time zone (note that blank space has been added before the left brace).

Leave a Reply