1

I want to change date format depends on logged in user locale.

Date start_date = 2017-25-11;

If user is from China, start_date should display as:

2017-25-11

If user from US, start_date should display as:

11/25/2017

If user from India, start_date should display as:

25/11/2017 

How can I convert start_date (date field) dynamically depending on logged in user locale?

1
  • 2
    you can use apex:outfield to display the date field. it will automatically convert into current user's locale
    – Ratan Paul
    May 11, 2017 at 13:04

1 Answer 1

9

There is a Date method for that:

format()

Returns the Date as a string using the locale of the context user

Here are what those formats would look like:

LocaleSidKey    toLabel(LocaleSidKey)      Output
=====================================================
zh_CN           Chinese (China)            2017-11-25
en_US           English (United States)    11/25/2017
en_IN           English (India)            25/11/2017
1
  • Can I do this same thing in javascript? Apr 5, 2019 at 5:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .