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
Rocio VivancoRocio Vivanco 

How can a date be displayed in the format dd/mm/yyyy in Visualforce?

Hi all,

I am trying to display/retrieve a given date in the format dd/mm/yyyy, but without success til now.

What is being displayed is this:

User-added image

My code in Visualforce is this:
 
<td style="white-space:nowrap;">
                  <apex:inputText value="{0,StartDateTime,MM'/'dd'/'yyyy}" disabled="true" >
                   <apex:param value="{!evento.StartDateTime}" /> 
                  <apex:inputText>
</td>
Even if I replace "inputText" by "outputText", under my problems list appears "disabled not compatible with outputtext.

StartDateTime is a field in the Event object and it is shown that way probably because my time zone is a British timezone:

User-added image

Users want the timezone in English and not Spanish.
Is there any form to display the date time in the format dd/mm/yyyy? (example: 17/05/2017)

I would appreciate tips.
 
Best Answer chosen by Rocio Vivanco
Rakesh Thota 15Rakesh Thota 15
Hi Rocio Vivanco,

if all you need is the current date printed out in that format then you can use this:
 
<apex:outputText value="{0, date,  dd / MM / yyyy}">
 <apex:param value="{!NOW()}" />
</apex:outputText>

Hope this helps you!


Best Regards,
Rakesh Thota.

All Answers

Rakesh Thota 15Rakesh Thota 15
Hi Rocio Vivanco,

if all you need is the current date printed out in that format then you can use this:
 
<apex:outputText value="{0, date,  dd / MM / yyyy}">
 <apex:param value="{!NOW()}" />
</apex:outputText>

Hope this helps you!


Best Regards,
Rakesh Thota.
This was selected as the best answer
Shiva RajendranShiva Rajendran
Hi Rocio,
Use the below code , it gives an inputDateField and displays that in dd/mm/yyyy format

Vf page  :
 
<apex:page controller="DmVFcheck_CC" >
    <apex:form>
        
        <apex:inputField value="{!evento.StartDateTime}"  >  
          <apex:actionSupport event="onchange" action="{!functionName}" reRender="renderOp1"/>    
          </apex:inputField>
        <apex:outputPanel id="renderOp1">
            
            <apex:outputText value="{0, date,dd MMMM yyyy}">
               
            <apex:param value="{!evenDate}" /> 
         </apex:outputText>
        
          
            </apex:outputPanel>
       
</apex:form>
</apex:page>

Controller code  :
 
public class DmVFcheck_CC {
    public event evento{get;set;}
    public Date evenDate{get;set;}
    public Integer ii{get;set;}
    public DmVFcheck_CC()
    {
        evento=new Event();
        evento.StartDateTime=System.now();
        evenDate=evento.StartDateTime.date();
        ii=0;
    }

    public PageReference functionName()
    {
        System.debug('function called');
        evenDate= evento.StartDateTime.date();
        //Time tt= System.now().time();
       //  evento.StartDateTime= DateTime.newInstance(evenDate, tt); 
       // ii++;
        return null;
    }
}

Let me know if you need further help on the code part.
Thanks and Regards,
Shiva RV
 
Rocio VivancoRocio Vivanco
Thanks guys for your answers.
I have used both versions of you, but one of them worked best just replacing NOW() by evendate.