3

So:

{!relatedTo.K__EndDate__c}

Gives me: "Wed Apr 02 00:00:00 GMT 2014"

What would I use if I want:

"Wed Apr 02 2014"

i.e. suppressing the time part.

Thx.

5

You can use a parameterised outputText with a Java-style format string in your Visualforce page to do this:

<apex:outputText value="{0,date,EEE MMM dd yyyy}">
    <apex:param value="{!relatedTo.K__EndDate__c}" /> 
</apex:outputText>

This is covered in more detail in the documentation here.

Use with nested param tags to format the text values, where {n} corresponds to the n-th nested param tag. The value attribute supports the same syntax as the MessageFormat class in Java. See the MessageFormat class JavaDocs for more information.

  • Is there a locale-respecting way to do this? – Keith C Mar 28 '14 at 11:12
  • @KeithC You can use .format() in a controller to produce a formatted string in the user's locale. As soon as you start getting into specific formats such as the above it's very hard to respect locale. Salesforce provides short, medium and long date formats, but these are always US localised, despite the documentation suggesting otherwise. This is talked about in this answer (salesforce.stackexchange.com/a/488/5460), which seems to infer that this will never be fixed. – Alex Tennant Mar 28 '14 at 11:29
  • You can also use apex:outputField which respects locale (unlike apex:outputText, but you have no control over the format when you do this, it just uses the default for the user's locale. – Alex Tennant Mar 28 '14 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.