Visualforce: How do I print the Current Date?
Asked Answered
T

2

5

How do I print the current date on Visualforce?

Stuff like Today(), System.now, doesn't work.

Haven't been able to find any documentation or stackoverflow questions regarding this subject.

Tanning answered 31/1, 2012 at 22:16 Comment(0)
A
5

In your controller, create a property:

public Date Today { get { return Date.today(); }}

In the VF page, try using:

<apex:outputText value="{0,date}">
    <apex:param value="{!Today}" />
</apex:outputText>

Details on formatting the date can be found here and here.

Appellate answered 31/1, 2012 at 22:26 Comment(0)
C
17

Visualforce has Data and Time functions too, you can use {!NOW()} or {!TODAY()}.

For more details go here

Claypool answered 2/2, 2012 at 2:46 Comment(1)
I think this answer is by far the best.Flourish
A
5

In your controller, create a property:

public Date Today { get { return Date.today(); }}

In the VF page, try using:

<apex:outputText value="{0,date}">
    <apex:param value="{!Today}" />
</apex:outputText>

Details on formatting the date can be found here and here.

Appellate answered 31/1, 2012 at 22:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.