[SalesForce] How to change date format depends on user locale

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?

Best Answer

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