Date Snippet to retrieve actual date (without conversion to current user locale)

  • 1
  • Question
  • Updated 4 years ago
I have a snippet which retrieves a DateTime field from multiple rows in a child model, converts each date to a string, and concatenates each date with a line break into a long text field on the parent model. (So that I can then send an html email template with this long text field included).

Snippet below:
var $ = skuid.$;
var parentEnquiry = skuid.model.getModel('CharterOpParent');
var parentRow = parentEnquiry.getFirstRow();
var Sectors = skuid.model.getModel('Sectors');
var descField = '';
$.each(Sectors.data, function (i, row){    //iterate over the rows
    var jsDateTime = skuid.time.parseSFDate(row.stack__Date__c);
    var jsDate = jsDateTime.toDateString();

    descField += jsDate + '\n';
    console.log(jsDateTime);
    console.log(jsDate);
});
console.log('************');
console.log(descField);
parentEnquiry.updateRow(parentRow,'stack__Special_Requirements__c',descField);


The issue with this is that it appears to be converting the time displayed in the browser into the current user's locale. For example, if I enter two child rows with dates of:

26/11/2014 23:00
29/11/2014 00:00

Then the output the snippet populates into the long text field is:

Wed Nov 26 2014
Fri Nov 28 2014




Is there a different method to have this snippet retrieve the 'actual' time displayed on the users browser? (without any conversion for current user's locale?)



 
Photo of Greg Jarrett

Greg Jarrett

  • 3,496 Points 3k badge 2x thumb

Posted 4 years ago

  • 1
Photo of Ben Hubbard

Ben Hubbard, Employee

  • 12,490 Points 10k badge 2x thumb
Hi Greg,

Is there a particular timezone you would like to use?  For instance do you want to always use the timezone of your location?  Or something like GMT?  What is the timezone of the person doing the data entry of the datetimes in the first place?
Photo of Greg Jarrett

Greg Jarrett

  • 3,496 Points 3k badge 2x thumb
Hi Ben,

Because we're deploying in a managed package our users will potentially have many different time zones. What I'd really like to do is capture the time on the user's browser.

Users refer to this as the 'local time' at point of departure for a trip (which is likely to be in a different time zone again from that of the user). So I really want to capture this 'local time' which is what the user sees in the browser. 

Is that possible?