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).
<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).
how to print previous year
It is not available in System Class: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_system.htm.
You can use addMonths() in apex. Check this for sample code: https://www.infallibletechie.com/2022/01/how-to-show-datetime-in-visualforce.html