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
AndyuxAndyux 

Apex local date formating

I am displaying a few dates using 
<apex:outputText value="{0,date,MMMM' 'dd', 'yyyy}"> <apex:param value="{!StrategicSales__c.Opportunity__r.CloseDate}" /> </apex:outputText>
Which is OK. Any way i can display the date in mm/dd/yyyy OR dd/mm/yyyy - depending on the user local setting? i have US and other users.
 
KapilCKapilC
Hi Andy,

Can you please try this code.

format()
 
Converts the date to the local time zone and returns the converted date as a formatted string using the locale of the context user. If the time zone cannot be determined, GMT is used.
DateTime myDateTime = DateTime.newInstance(1993, 6, 6, 3, 3, 3);
system.assertEquals('6/6/1993 3:03 AM', mydatetime.format());
 
format(dateFormatString)
Datetime myDT = Datetime.now();
String myDate = myDT.format('h:mm a');

Thanks,
Kapil