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
SreejbSreejb 

Convert from this string to date format

Hi friends,

I want to convert this value Sun Jun 12 00:00:00 GMT 2016 into date format 06/12/2016(MM/DD/YYYY) format. I am using custom controller. While fetching data from time_entry object its showing in VF page like this Sun Jun 12 00:00:00 GMT 2016. So while showing in page I want dd/mm/yyyy format. Here I attached my code . Please help on this.
 
<apex:page standardController="Time_Entry__c" showHeader="false" sidebar="false" standardStylesheets="true" recordSetVar="timelist" >
  <apex:form >
      <apex:pageBlock title="Time Entry Page" >
          <apex:pageBlockButtons location="top" >
                  <apex:commandButton value="Select"/>
                   </apex:pageBlockButtons>   
         
            <apex:selectList multiselect="false" size="1"  >
                  <apex:selectOption itemValue="MON" itemLabel="--Month--">  </apex:selectOption> 
                  <apex:selectOption itemValue="JAN" itemLabel="January">  </apex:selectOption> 
                  <apex:selectOption itemValue="FEB" itemLabel="February"> </apex:selectOption>
                  <apex:selectOption itemValue="MAR" itemLabel="March"> </apex:selectOption>
                  <apex:selectOption itemValue="APR" itemLabel="April"> </apex:selectOption>     
                  <apex:selectOption itemValue="MAY" itemLabel="May"> </apex:selectOption> 
                  <apex:selectOption itemValue="JUN" itemLabel="June"> </apex:selectOption> 
                  <apex:selectOption itemValue="JUL" itemLabel="July"> </apex:selectOption> 
                  <apex:selectOption itemValue="AUG" itemLabel="August"> </apex:selectOption> 
                  <apex:selectOption itemValue="SEP" itemLabel="September"> </apex:selectOption> 
                  <apex:selectOption itemValue="OCT" itemLabel="October"> </apex:selectOption> 
                  <apex:selectOption itemValue="NOV" itemLabel="November"> </apex:selectOption> 
                  <apex:selectOption itemValue="DEC" itemLabel="December"> </apex:selectOption> 
              </apex:selectList>
              <apex:selectList multiselect="false" size="1">
                  <apex:selectOption itemValue="YEAR" itemLabel="--Year--">  </apex:selectOption> 
                  <apex:selectOption itemValue="2016" itemLabel="2016">  </apex:selectOption> 
                  <apex:selectOption itemValue="2017" itemLabel="2017">  </apex:selectOption> 
                  <apex:selectOption itemValue="2018" itemLabel="2018">  </apex:selectOption> 
                  <apex:selectOption itemValue="2019" itemLabel="2019">  </apex:selectOption> 
                  <apex:selectOption itemValue="2020" itemLabel="2020">  </apex:selectOption> 
              </apex:selectList>
                   
                   
        
                <apex:pageBlockTable value="{!timelist}" var="t" columns="4">
                <apex:column width="25%" > <apex:outputLink value="/apex/te_detail?idx={!t.id}">{!t.name}</apex:outputLink> </apex:column>
                <apex:column value="{!t.Time_From_Date__c}"/>
                <apex:column value="{!t.Time_To_Date__c}"/>
                <apex:column value="{!t.Status__c}"/>
          </apex:pageBlockTable>         
         
          
      </apex:pageBlock>
  </apex:form>
</apex:page>

Controller is
 
Public class Wrapperclassdemo{
    /* Our Wrapper Class */
    Public Class Tablerow{
        Public Date Fromdate {get;set;}
        Public Date Todate {get;set;}
        Public String Status {get;set;}
        Public String Name {get;set;}
        
    
    }
    /*Public Property that will hold all the Tablerows and our PageBlockTable can use this Variable   to get the whole List of rows*/
    Public List<Tablerow> Rowlist {get;set;}
    
    /*Constructor that runs a SOQL to get all the Records and build the List. This get executed automatically on the Page Load.*/
    Public Wrapperclassdemo(){
        Rowlist = new List<Tablerow>();
        Tablerow tr;
        /*Building the List of TableRows*/
        /*Fetch all the Contacts and then build the List*/
        
        

    } 
    
   Public void select1(){
   
          for(Time_Entry__c tm : [Select Name, Time_From_Date__c,Time_To_Date__c,Status__c from Time_Entry__c ]){
            Tablerow tr = new Tablerow();
            tr.Fromdate = tm.Time_From_Date__c;
            tr.Todate = tm.Time_To_Date__c;
            tr.Status = tm.Status__c;
            tr.Name = tm.Name;
            
            /*Add the TableRow to the List then and there*/
            
            Rowlist.add(tr);
                
        }
   
   
   
   }
}

 
Best Answer chosen by Sreejb
PavanKPavanK
Could you please try with below code
 
<apex:page standardController="Time_Entry__c" showHeader="false" sidebar="false" standardStylesheets="true" recordSetVar="timelist" >
  <apex:form >
      <apex:pageBlock title="Time Entry Page" >
          <apex:pageBlockButtons location="top" >
                  <apex:commandButton value="Select"/>
                   </apex:pageBlockButtons>   
         
            <apex:selectList multiselect="false" size="1"  >
                  <apex:selectOption itemValue="MON" itemLabel="--Month--">  </apex:selectOption> 
                  <apex:selectOption itemValue="JAN" itemLabel="January">  </apex:selectOption> 
                  <apex:selectOption itemValue="FEB" itemLabel="February"> </apex:selectOption>
                  <apex:selectOption itemValue="MAR" itemLabel="March"> </apex:selectOption>
                  <apex:selectOption itemValue="APR" itemLabel="April"> </apex:selectOption>     
                  <apex:selectOption itemValue="MAY" itemLabel="May"> </apex:selectOption> 
                  <apex:selectOption itemValue="JUN" itemLabel="June"> </apex:selectOption> 
                  <apex:selectOption itemValue="JUL" itemLabel="July"> </apex:selectOption> 
                  <apex:selectOption itemValue="AUG" itemLabel="August"> </apex:selectOption> 
                  <apex:selectOption itemValue="SEP" itemLabel="September"> </apex:selectOption> 
                  <apex:selectOption itemValue="OCT" itemLabel="October"> </apex:selectOption> 
                  <apex:selectOption itemValue="NOV" itemLabel="November"> </apex:selectOption> 
                  <apex:selectOption itemValue="DEC" itemLabel="December"> </apex:selectOption> 
              </apex:selectList>
              <apex:selectList multiselect="false" size="1">
                  <apex:selectOption itemValue="YEAR" itemLabel="--Year--">  </apex:selectOption> 
                  <apex:selectOption itemValue="2016" itemLabel="2016">  </apex:selectOption> 
                  <apex:selectOption itemValue="2017" itemLabel="2017">  </apex:selectOption> 
                  <apex:selectOption itemValue="2018" itemLabel="2018">  </apex:selectOption> 
                  <apex:selectOption itemValue="2019" itemLabel="2019">  </apex:selectOption> 
                  <apex:selectOption itemValue="2020" itemLabel="2020">  </apex:selectOption> 
              </apex:selectList>
                   
                   
        
                <apex:pageBlockTable value="{!timelist}" var="t" columns="4">
                <apex:column width="25%" > <apex:outputLink value="/apex/te_detail?idx={!t.id}">{!t.name}</apex:outputLink> </apex:column>
                <apex:column value=" {!t.Time_From_Date__c}"/>
                <apex:column value=" {!t.Time_To_Date__c}"/>
                <apex:column value=" {!t.Status__c}"/>
          </apex:pageBlockTable>         
         
          
      </apex:pageBlock>
  </apex:form>
</apex:page>

 

All Answers

PavanKPavanK
Could you please try with below code
 
<apex:page standardController="Time_Entry__c" showHeader="false" sidebar="false" standardStylesheets="true" recordSetVar="timelist" >
  <apex:form >
      <apex:pageBlock title="Time Entry Page" >
          <apex:pageBlockButtons location="top" >
                  <apex:commandButton value="Select"/>
                   </apex:pageBlockButtons>   
         
            <apex:selectList multiselect="false" size="1"  >
                  <apex:selectOption itemValue="MON" itemLabel="--Month--">  </apex:selectOption> 
                  <apex:selectOption itemValue="JAN" itemLabel="January">  </apex:selectOption> 
                  <apex:selectOption itemValue="FEB" itemLabel="February"> </apex:selectOption>
                  <apex:selectOption itemValue="MAR" itemLabel="March"> </apex:selectOption>
                  <apex:selectOption itemValue="APR" itemLabel="April"> </apex:selectOption>     
                  <apex:selectOption itemValue="MAY" itemLabel="May"> </apex:selectOption> 
                  <apex:selectOption itemValue="JUN" itemLabel="June"> </apex:selectOption> 
                  <apex:selectOption itemValue="JUL" itemLabel="July"> </apex:selectOption> 
                  <apex:selectOption itemValue="AUG" itemLabel="August"> </apex:selectOption> 
                  <apex:selectOption itemValue="SEP" itemLabel="September"> </apex:selectOption> 
                  <apex:selectOption itemValue="OCT" itemLabel="October"> </apex:selectOption> 
                  <apex:selectOption itemValue="NOV" itemLabel="November"> </apex:selectOption> 
                  <apex:selectOption itemValue="DEC" itemLabel="December"> </apex:selectOption> 
              </apex:selectList>
              <apex:selectList multiselect="false" size="1">
                  <apex:selectOption itemValue="YEAR" itemLabel="--Year--">  </apex:selectOption> 
                  <apex:selectOption itemValue="2016" itemLabel="2016">  </apex:selectOption> 
                  <apex:selectOption itemValue="2017" itemLabel="2017">  </apex:selectOption> 
                  <apex:selectOption itemValue="2018" itemLabel="2018">  </apex:selectOption> 
                  <apex:selectOption itemValue="2019" itemLabel="2019">  </apex:selectOption> 
                  <apex:selectOption itemValue="2020" itemLabel="2020">  </apex:selectOption> 
              </apex:selectList>
                   
                   
        
                <apex:pageBlockTable value="{!timelist}" var="t" columns="4">
                <apex:column width="25%" > <apex:outputLink value="/apex/te_detail?idx={!t.id}">{!t.name}</apex:outputLink> </apex:column>
                <apex:column value=" {!t.Time_From_Date__c}"/>
                <apex:column value=" {!t.Time_To_Date__c}"/>
                <apex:column value=" {!t.Status__c}"/>
          </apex:pageBlockTable>         
         
          
      </apex:pageBlock>
  </apex:form>
</apex:page>

 
This was selected as the best answer
VamsiVamsi
Hi ,

In the column tage put a space before date fields(I mean between double quote and { ) like :

<apex:column value=" {!t.Time_From_Date__c}"/>
  <apex:column value=" {!t.Time_To_Date__c}"/>

Please mark as best answer if it helps 
SreejbSreejb
The out put is
PavanKPavanK
Yes In my above code i have added space, so code i have posted should work
SreejbSreejb
Thank u pawan and vamshi krishnana.....Its working fine.
Krishna SambarajuKrishna Sambaraju
Here are the different ways to display the dates on visualforce page.
<!-- formatting in the visual force page -->
<apex:column headerValue="Date">
    <apex:outputText value="{0, date, dd/MM/yyyy}">
        <apex:param value="{!t.Time_From_Date__c}" />
    </apex:outputText>
</apex:column>

<!-- Using the output field, which displays the format as per time zone settings-->
<apex:column headerValue="Date">
         <apex:outputField value="{!t.Time_From_Date__c}"/>
 </apex:column>
Hope this helps.

Regards,
Krishna.