[SalesForce] How to know date format of Users

How to know the date format of the user in salesforce.
Basically I want to perform some operation based on user's date format.
Like:

  If(date_format == dd/mm/yyyy)
{
   do this
}
if(date_format == mm/dd//yyyy)
{
   do this
}

I know we can use Map to store the locale as key and date format as values and then query the locale and get the date format, but it is very lengthy and it will also increase the no. of lines in code.

Best Answer

To see the date format of your company instance, you can just use date.format() //on any date field It will give you the date format set in your salesforce instance.

other than that you can use Userinfo.getlocale() to get the locale of the current user.

If you want to capture date and time in your VF page with the format just use System.now.format()

Related Topic