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
Drew1815Drew1815 

Localized Date with Visualforce

I am trying to localize a date field in Visualforce and I can't apply the end-users locale. I know I can use the outputField component but I want to manipulate the positioning and output differently. So I am trying to use outputtext component. I am able to output it as I like, but I am not able to apply the end-users locale.

 

Here is a snippet of code:

 

 

<apex:page controller="controllertest" >
<apex:form>
 <apex:outputText value="The formatted time right now is: 
         {0,date, EEEEEEE, d MMM yyyy}">
       <apex:param value="{!d}" />
   </apex:outputText>

</apex:form>
</apex:page>

 

 

No matter what locale or language the user is logged in with, I get "The formatted time right now is: Wednesday, 27 Oct 2010".

 

Anyone know how I can apply locale to this VF snippet?

Pradeep_NavatarPradeep_Navatar

Tryout this sample code :

 

           <apex:outputText value="The formatted time right now is:{0,date,yyyy.MM.dd G 'at' HH:mm:ss z}">

                <apex:param value="{!NOW()}" />

            </apex:outputText>

 

Hope this helps.

SSRS2SSRS2

Using above example cannot be localized time zone to user's locale but using simple apex method you can do it

Ex:

Apex Code:

 

public string getDateTimeWithLocale()
{
  return  system.Now().format('EEEEEEE,d MMM yyyy z',  'CST'); //GMT(get TimeZone from User Table)
}

VF Block

 

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

 

 

 

-Suresh

Drew1815Drew1815

That applies the timezone dynamically but it does not render the day of the week based off language. It doesn't convert Friday to viernes (for example).