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
Ugesh.galiUgesh.gali 

How to get user locale date format in salesforce or date format based on user locale

I have a datetime field which some users are in INDIA and some user are in USA

I have to dispaly dd/mm/yyyy for india and mm/dd/yyyy for us

 

Is there any way to get the time formats based on the user selected locals in apex class

 

how to get dateformat based on user locale

Shashikant SharmaShashikant Sharma

Use Date.today()

Prafull G.Prafull G.

Use format method in apex to achieve it.

something like Date.format('dd/mm/yyyy')

 

you can create a map to hold locale as key and format as value and then this map can be used to find the correct date format on runtime.

Use UserInfo.getLocale() to find current users locale.

 

hope this helps.

 

with best,

crmtech21

Ugesh.galiUgesh.gali

Thnaks for the replies.

I got solution by googling. I found  an article.

 

http://www.interactiveties.com/b_locale_datetime.php.

 

Thankyou.

ugesh