If you query a Date or a DateTime field with JavaScript Remoting the value returned will be the number of milliseconds since 1970 such as, 1359147598000. Good for data consistency...bad for user experience.
var date = new Date(1359147598000);
console.log(date);
console.log(date.toDateString());
console.log(date.toLocaleDateString());
Will result the following output:
Fri Jan 25 2013 12:59:58 GMT-0800 (PST)
Fri Jan 25 2013
1/25/2013
For United States users the date should format as 1/25/2013. For the mates in UK it should format as 25/01/2013.
You would think toLocaleDateString() would be the solution but it appears very brittle and it doesn't even seem to work for when I change my computers locale.
So what is the best way to format and display Date/DateTime values in the users local format when using JavaScript Remoting?
Thanks.
window.UserContexthaving a JS-ready string for the user'sdateFormaton it, you might also take a peek at the functions available withinwindow.DateUtil, there may be some useful bits there too. For instance, converting and parsing dates and detecting if the user's browser timezone is the same as their SFDC user-record timezone.DateUtil.isBrowserAndSystemTimezoneSame();– Mark Pond Feb 19 at 23:17