+ Start a Discussion
UmapenUmapen 

date format on visual force page

In my visual force page I have the following line that display date : 1/21/2010 9:37 PM

<apex:outputField value="{!invitation.Account_group__r.Submission_Due_Date__c}"/>

 

 

I want to display date as : Jan 21, 2010 9.37 PM pst

 

Do I have to convert to string in my controller and display parsed data in visual force page?

or

Is there any format that I can give in my style(css) that will display date in the format I want?

 

Thanks

 

Best Answer chosen by Admin (Salesforce Developers) 
Shri kalkoteShri kalkote

It's all about the matter of one 'space'. If you insert the space in value attribute of outputField like:

<apex:outputField value=" {!invitation.Account_group__r.Submission_Due_Date__c}"/>

it will display time in your local timezone and if you remove the space from it like this:

<apex:outputField value="{!invitation.Account_group__r.Submission_Due_Date__c}"/>

it will display time in GMT format.

All Answers

bob_buzzardbob_buzzard
I've found that I have to format the date in the controller.  While you can use fields to back tags, you can't execute the methods available for the field type.  I don't know about css, but you could probably do something using JavaScript.
UmapenUmapen

Here is the posting I found for DateTime format, but do not know how to do the date only field format.

 

http://community.salesforce.com/sforce/board/message?board.id=apex&message.id=7876

 

 

Date Dt = invitation.start_date__c;

String starDate = dt.format('mmm d); not working error in format

 

bob_buzzardbob_buzzard

I don't think you can format a date like that - you'll have to convert it to a date time and format that.

 

UmapenUmapen
Here is the solution to format date field I used. if anyone know better solution let me know

public String getTravelstartDate(){ String TrvstartDate=' '; DateTime Dt = DateTime.valueOf(invitation.Travel_start_date__c +' 00:00:00'); TrvstartDate = Dt.format('MMM d, yyyy'); return TrvstartDate; }

 

Here is the link to more from documentation for more examples of DateTime format  http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html

 

<apex:outputText value="{!TravelstartDate}" />

 

danlatdanlat

Hi All,

 

You can also do:

 

<apex:outputText value="Dated: {0,date,E MMM d yyyy}"> <apex:param value="{!NOW()}" /> </apex:outputText>

 Format codes in above post link to Java site.

DanielTDanielT

Hi,

 

I also use the following;

 

<apex:outputText value="{0,date,dd'/'MM'/'yyyy}">
        <apex:param value="{!Non_Stores_Offers__c.Start_Date__c}"/>
</apex:outputText>
Shri kalkoteShri kalkote

It's all about the matter of one 'space'. If you insert the space in value attribute of outputField like:

<apex:outputField value=" {!invitation.Account_group__r.Submission_Due_Date__c}"/>

it will display time in your local timezone and if you remove the space from it like this:

<apex:outputField value="{!invitation.Account_group__r.Submission_Due_Date__c}"/>

it will display time in GMT format.

This was selected as the best answer
sniper_semajsniper_semaj

<apex:outputText value=" {!dto.o.Amount}">
</apex:outputText>

 

I did this on the amount field. but unfortunately when amount is long. ex. 10000000 this will be converted to exponetial number results like 1.0E+7. is there's way to fix this?

 

 

cg512cg512

It's all about the matter of one 'space'. If you insert the space in value attribute of outputField like:

<apex:outputField value=" {!invitation.Account_group__r.Submission_Due_Date__c}"/>

it will display time in your local timezone and if you remove the space from it like this:

<apex:outputField value="{!invitation.Account_group__r.Submission_Due_Date__c}"/>

it will display time in GMT format. "

 

You nailed it! And what an easy fix. Thanks!