Scavanger
Scavanger

Reputation: 23

Change string to date in certain timezone

I have a date as string in format yyyy-mm-dd & timezone stored in another variable t in format like (GMT -05:00) Eastern Time. I want to obtain the date object with this date in this timezone in Javascript/appscript. The time in date object should be 00.00.00.000 only & timezone should as in the variable.

Upvotes: 0

Views: 48

Answers (1)

Cooper
Cooper

Reputation: 64140

function dateStringsForDifferentTimezones() {
  let oA = [['Date String','TimeZone']];
  for (let i = 0; i < 24; i++) {
    oA.push([Utilities.formatDate(new Date(), `GMT-${i}`, "E MMM dd, yyyy HH:mm:ss"),`${-i}`]);
  }
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName('Sheet1');
  sh.getRange(1, 1, oA.length, 2 ).setValues(oA);
}

Upvotes: 1

Related Questions