Ok, in this case, if I have custom object that contain a date field. After I query a record using Ajax toolkit. That date field become a Date object in the recordset. So is there a function or something to display it according to the locale setting? How do I do that? And If I need to update this field, how do I save it back to the database?
var dformat; // holds the format string that we think date should be shown with
then later, somewhere near sforceClient.init() Code:
sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_70}"); var uInfo = sforceClient.GetUserInfo(); // has the locale dformat = Sforce.Util.ParseDateFormat("{!Today}",uInfo.userLocale);
// create a date using Locale format var l_textField = Sforce.Util.FormatDate (so.get('CreatedDate'), dformat + " HH:mm") // use dformat
Code:
/* ParseDateFormat ( "26/02/2006" ) == "d/M/y" * given a date string, report which format it is in, * used to detect locale date formats */ Sforce.Util.ParseDateFormat = function(val,lang) {lang = lang+""; /*Lang comes from API Name: LocaleSidKey Type: picklist */ var preferEuro = true; if ( /US/.test(lang) ) preferEuro = false; generalFormats=new Array('y-M-d','MMM d, y','MMM d,y','y-MMM-d','d-MMM-y','MMM d'); monthFirst=new Array('M/d/y','M-d-y','M.d.y','MMM-d','M/d','M-d'); dateFirst =new Array('d/MM/y','d-M-y','d.M.y','d-MMM','d/M','d-M'); var checkList= new Array(generalFormats,preferEuro—dateFirst:monthFirst,preferEuro–monthFirst:dateFirst); var d=null; for (var i=0; i<checkList.length; i++) { var l=checkList[i]; for (var j=0; j<l.length; j++) { d=Sforce.Util.GetDateFromFormat(val,l[j]); if (d!=0) { return l[j] } } } return "M/d/y"; // a default
}
I
could just write a function which will return a format for each and
every userLocale supported, but i didn't for some shortsighted reason i
can't recall. if anyone has / writes a UserLocale --> date
format using Switch(userLocale) { case .... rountine, please post, i
think that would be the real way to go. To store a date back
into a dynabean, there is a function in the toolkit called
Sforce.Util.ParseDate() which looks a lot like the routine above but
returns a date object which dynabean.set() can accept.
Can this approach be used to overcome a problem I have with locales at the moment?
If my user is of US locale, then when they enter a date into s-control via calendar widget all is OK. If however they are of locale that uses DD-MM-YYYY date format, then the date entered via the widget is parsed incorrectly, and day and month are switched.
Dont know how to handle this situation - any suggestions?
Im having trouble understanding how or what this does Im sorry - can I use this routine to take a date string from user locale eu_AU, and convert it to eu_US?
Just a little question for my culture can you explain this ligne of code if ( /US/.test(lang) )
I am using your code plus something I have crafted myself but it is to understand
Thanks for an update on this.
Regards It is important to know that javascript is considering all date by default as mm/dd/yyyy
Just for you:smileyvery-happy: Code: function Return_LocaleDate(p_string) { var date_order= dformat.split(/\W/); switch (date_order[0].charAt(0).toLowerCase()) { case 'm': A = p_string.split(/\D/); return(new Date(A[2],A[0]-1,A[1])); break; case 'd': A = p_string.split(/\D/); return(new Date(A[2],A[1]-1,A[0])); break; default: return null; } } Bye
I am facing the same problem.We have generalised s-control to use MM/dd/yyyy format and ask our users to change regional settings date format.
Applicaton behaves smoothly for all US users.Recently one of our users faced problem of date widget converting the date into dd/mm/yyyyy.He has verified that he sticks to the date format that is generalised for our application user.
has anybody clue on this?
We are not using Ajax tool kit for S-control development.our application is purely HTML & Javascript dependent with SOAP & XML messaging.Can somebody help out!
at the top of the file, throw up a global
Code:
then later, somewhere near sforceClient.init()
Code:
I could just write a function which will return a format for each and every userLocale supported, but i didn't for some shortsighted reason i can't recall.
if anyone has / writes a UserLocale --> date format using Switch(userLocale) { case .... rountine, please post, i think that would be the real way to go.
To store a date back into a dynabean, there is a function in the toolkit called Sforce.Util.ParseDate() which looks a lot like the routine above but returns a date object which dynabean.set() can accept.
Message Edited by Ron Hess on 04-03-2006 09:53 PM
If my user is of US locale, then when they enter a date into s-control via calendar widget all is OK.
If however they are of locale that uses DD-MM-YYYY date format, then the date entered via the widget is parsed incorrectly, and day and month are switched.
Dont know how to handle this situation - any suggestions?
Regards,
Carl_V
Just a little question for my culture
can you explain this ligne of code
if ( /US/.test(lang) )
I am using your code plus something I have crafted myself but it is to understand
Thanks for an update on this.
Regards
It is important to know that javascript is considering all date by default as mm/dd/yyyy
Just for you:smileyvery-happy:
Code: function Return_LocaleDate(p_string) {
var date_order= dformat.split(/\W/);
switch (date_order[0].charAt(0).toLowerCase()) {
case 'm':
A = p_string.split(/\D/);
return(new Date(A[2],A[0]-1,A[1]));
break;
case 'd':
A = p_string.split(/\D/);
return(new Date(A[2],A[1]-1,A[0]));
break;
default: return null;
}
}
Bye
Then you can use the DateFormat() to generate other dates (usint dates in beans) which are in the users' locale format.
so it's almost what you want, but only returns the format.
Hi All,
I am facing the same problem.We have generalised s-control to use MM/dd/yyyy format and ask our users to change regional settings date format.
Applicaton behaves smoothly for all US users.Recently one of our users faced problem of date widget converting the date into dd/mm/yyyyy.He has verified that he sticks to the date format that is generalised for our application user.
has anybody clue on this?
We are not using Ajax tool kit for S-control development.our application is purely HTML & Javascript dependent with SOAP & XML messaging.Can somebody help out!
Thanks,
K-SFDC developer.