Printing Formated Current Time and/or Date - El Toro - Find articles about Visualforce, Apex, and Salesforce in general

Print Preview

Printing Formated Current Time and/or Date

The current date and/or time, can be displayed quickly using ths code:


or you could use this code, which allows you to set some things like CSS styles

<apex:outputText value="{!Now()}" />

But you can also change the format the date/time is shown...

<apex:outputText value="{0, date, MMMM dd, yyyy @ hh:mm:ss aa z}">
	<apex:Param value="{!Now()}" />

You may also get the fomating string from Apex, which allows you to re-use the same format.

<apex:outputText value="{0, date, {!DateFormat}}">
    <apex:Param value="{!Now()}" />

In the Apex code, you would have something like this:

public String getDateFormat() {
    return 'MMMM dd, yyyy @ hh:mm:ss aa z';

The full reference as to what can be used on the third parameter can be found here:

comments powered by Disqus

© El Toro . IT @ 2013
Andrés Pérez