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
Vishal_ThoriyaVishal_Thoriya 

how to format the date and time

hi,

 

i am having issue of formating the date........

 

can anybody solve this?

 

i am retrieving the created date value is like : (Thu Nov 03 09:39:35 GMT 2011)

 

i want to convert it into this format : (11/2/2011 8:57 AM)

 

my code is like this:

 

requirementCommentObj = [select Comment__c, Requirement__c, Commented_By__c,Commented_By__r.Name,createdDate,Name from Requirement_Comment__c];

 

for(Integer i = 0; i < requirementCommentObj.size(); i++)           

{                 

requirementCommentObj[i].createdDate.format('yyyy-MM-dd HH:mm:ss');         

 }

return requirementCommentObj;

 

 

 

but this is not working.

any kind of help will be really apriciated......

thanks in advance............

 



Best Answer chosen by Admin (Salesforce Developers) 
Baktash H.Baktash H.

i had the same problem earlier. i think you want to display it on a VF, right?

 

try this:

 

              <apex:outputText value=" {0,date,dd.MM.yyyy - HH:mm}">
                <apex:param value="{!obj.CreatedDate}"/>
              </apex:outputText>

 

with this you get: DD.MM.YYYY - HH:mm

 

just modify the expression however you want.

All Answers

logontokartiklogontokartik

The format() method returns a String type field. In your code you are not saving the changed format; Try using a String field and display it in your VF page.

 

String formattedDate = requirementCommentObj[i].createdDate.format('yyyy-MM-dd HH:mm:ss');

 

return formattedDate;

 

Use formattedDate in the Visualforce page for display.

 

Thanks.

Baktash H.Baktash H.

i had the same problem earlier. i think you want to display it on a VF, right?

 

try this:

 

              <apex:outputText value=" {0,date,dd.MM.yyyy - HH:mm}">
                <apex:param value="{!obj.CreatedDate}"/>
              </apex:outputText>

 

with this you get: DD.MM.YYYY - HH:mm

 

just modify the expression however you want.

This was selected as the best answer
Vishal_ThoriyaVishal_Thoriya

i got the solution for this by using

<apex:outputText>

 

my question is already solved.......

 

thanks for the help....