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

Formatting Dates in S-Controls

In developing an S-Control I'm trying to do a combination of the following:
1) output certain Date values to the web page, formatting them according to the user's locale settings
2) fill in AND accept back Date values from editable Text Boxes (within HTML forms), again formatting these dates according to the user's locale settings
Questions are:
1) how can my S-Control (i.e. my javascript code) determine what the user's locale settings are?
2) having determined these, how can I convert date values to/from the user-visible format in a sensible way? i.e. is some kind of callable function available rather than just coding stuff like
if (locale == "English (United Kingdom)") {
  dateSeparator = "/";
  dateFormat = "dmy";
else if (locale == "English (United States)") {
  dateSeparator = "/";
  dateFormat = "mdy";
etc. etc.
Seems to me I'd be 'reinventing the wheel' if I did stuff like that - and it would also be a headache regarding testing and future maintainability.
Is there a better way to do this?
John Lewis
To get the user's locale, call getUserInfo().  Then access the userLocale property.  Regarding your 2nd quesiton, I'm not sure if there's a way to determine what format the date should be.  I don't know if that info is stored in salesforce.  If it's not, maybe you can create a custom field on the User entity that specifies the preferred date format for that user and leverage off that.
getUserInfo().userLocale seems to give me what I need - for part 1) anyway. :smileyhappy:
For the other part, I guess I can code a reusable javascript function and just add new locales to it if and when they get used.
However, this leads me to another question:
if I write such a function - called say getFormattedDate() - which takes a Date value and a Locale value as arguments, then where can I put it so that it can be used from ANY S-Control I write. Seems sensible that I'd put it in a .js file put where would I store this .js file? Can it be somehow uploaded to
You can create a new SControl of type Snippet and include it
in your other scontrol by using the INCLUDE tag, eg:



Thanks Cheenath