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
canonwcanonw 

Getting a Date Format for current user?

Does anyone know how to get date format for current user in scontrol?

The reason for date format is date picker. When I assign a date value to date picker, it must be locale oriented. Otherwise, s-control may assign date as DD/MM/YYY, instead of MM/DD/YYYY.

I know UserContext.dateFormat is the right variable.  But I can't find the method to get the value.  We have users around the world using several locale. So, hardcode is not an option.

Thanks in advance

Christine F.ax367Christine F.ax367
You can use standard Javascript functions to get date and time. The following sample adds 2 years to today's date and sets the date back.. there are other ways to do it like use the set function.. but this works for me. Be aware that getMonth() function returns month from 0 to 11, so you need to add one to it.
 

var now = new Date();

var year = now.getFullYear() + 2;

var day = now.getDate();

var month = now.getMonth()+ 1;

var closeDate = month + '/' + day + '/' + year;

Account.closeDate__c = closeDate;