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
sperurisperuri 

Convert the current date to date pattern like MM/DD/YY based on user locale.

I have a situation where i will get the user locale date in APEX using 

DateTime dateTimeToFormat = DateTime.valueOf( value );
Date dateToFormat = dateTimeToFormat.date();
String formattedDatewithUSER_LOCALE = dateToFormat.format();

For example, if the localecode is en_US and timezoneid is America/Los_Angeles, then the date i would get is 9/1/2016. 

In my java code, i would get all this info along with date, locale, time zone. Along with this, i would get a date like 2016-09-01 18:42:37 as input and the requirement is to format the input date to the user date based on the locale, timezone. 

Any sugesstions..?




 
saikrishna.Gsaikrishna.G
string dateval= Datetime.now().format('yyyy-MM-dd');  
sfdcMonkey.comsfdcMonkey.com
hi Ciphercloud Winter16
 try this formate 

 
Datetime yourDate = Datetime.now(); 
String dateOutput = yourDate.format('dd/MM/yyyy');

Thanks 
Please let me inform if it work :)
sperurisperuri
I need to convert the user locale date to the specific date pattern. I mean, if the user date based on locale is 9/1/2016, then i need to convert it to D/M/2016. If user date is 01/09/2016, then i need to convert it to DD/MM/YYYY. This is dynamic in nature based on user locale. Using this format DD/MM/YYYY from Apex, i will format input date in java (like 2016-09-01 18:42:37) to 01/09/2016. Is there any utility to convert the date into date pattern dynamically based on user locale.? 
Geo GeorgeGeo George

Try this

https://salesforcefeed.wordpress.com/2017/05/25/locale-conversion-and-the-formatting-of-the-datetime-fields-in-visualforce/

Thanks 
Please let me inform if it work :)