I printing out a date field, and normally the format is based on the user local setting (i am using french settings). the problem is that in chrome browser, the format is correct 'DD/MM/YYYY', but in the explorer the format is 'YYYY-MM-DD', that is weird.

Here is my code visualforce:

 <apex:input style="margin-right:20px" label="{!$Label.Date}" value="{!displayedWeek}" id="displayedWeek" type="date"> 

what shoud i change to get the correct format in both browsers ?

  • Please try <apex:inputField> instead of <apex:input>. Let me know if that works – Abhishek Feb 6 '17 at 11:08
  • 1
    With apex:input it uses HTML-5 date format which depends on user's machine (unless a browser overrides, here chrome does). For changing setting in internet explorer, refer this post. Ideally if you want to keep same behaviour everywhere, either use apex:inputField or some jQuery plugin. – Raul Feb 6 '17 at 12:37
  • I can not use InputField because it's not a standard object, it's giving an error when i try that. – Merabti Ibrahim Feb 6 '17 at 13:46

Use apex:outputText with the date method of the Datetime class and a valid date and time pattern string:

<apex:outputText value="{0,date,MM/dd/yyyy}"></apex:outputText>

Where value is a FormatElement with the following syntax:

{argumentIndex, formatType, formatStyle}

The ArgumentIndex value is a non-negative integer written using the digits '0' through '9', and represents an index into the arguments array passed to the format methods or the result array returned by the parse methods.

The FormatType and FormatStyle values are used to create a Format instance for the format element.


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.