It's hours I'm struggling to know why I don't get correct timeZone using this script ! I've used moment.js and moment-timezone and followed instruction explained here: Timezone conversion in a Google spreadsheet google-spreadsheet/40324587
I am trying to convert timezones usign following script:
var DT_FORMAT = 'YYYY-MM-DD HH:mm:ss';
function fromUtc(dateTime, timeZone) {
var from = m.moment.utc(dateTime,
DT_FORMAT);//https://momentjs.com/timezone/docs/#/using-
timezones/parsing-in-zone/
return from.tz(timeZone).format(DT_FORMAT);
}
function toUtc(dateTime, timeZone) {
var from = m.moment.tz(dateTime, DT_FORMAT,
timeZone);//https://momentjs.com/timezone/docs/#/using-timezones/parsing-
in-zone/
return from.utc().format(DT_FORMAT);
}
function myFunction(datetimeString,timeZone,format) {
var moment = new Date(datetimeString);
return Utilities.formatDate(moment, timeZone, format)
}
In my spreadsheet, the first column is date and time in standard GMT and I'm going to change date and time to different TimeZones which I wrote in next columns. Even-though I'm getting the date and time, but it is incorrect and I don't know how to fix it. Here is the link to Google sheet: https://docs.google.com/spreadsheets/d/1Tc0G2daX9FYIL354iyOffd06BtNPx5v-40KE5RtwDB4/edit?usp=sharing and here is the link to my script app: https://script.google.com/d/1u54McW1HBm-A2alno1DWWTFwk-vdok8ljwKfI_5htAHK-XrMt554YGLn/edit?usp=sharing
Update (replying to comment) : I use the function like this, I write in in a cell in spreadsheet: =fromUtc(A2, D1)