What is the best way to convert a UTC timestamp to a specific time zone using Luxon?
I have a UTC timestamp "YYYY-DD-MMTHH:MM:SSZ"
I've found two ways to convert the UTC timestamp to a time zone; either by specifying the time zone in 'fromISO' or using 'setZone':
const luxonUrl = 'https://cdnjs.cloudflare.com/ajax/libs/luxon/3.0.3/luxon.min.js';
eval(UrlFetchApp.fetch(luxonUrl).getContentText());
function utctotimezone() {
const timeZ = '2022-06-01T20:00:00Z';
const utctime = 'UTC';
const uktime = 'Europe/London';
const zISO = luxon.DateTime.fromISO(timeZ).toISO({suppressMilliseconds: true});
const utcISO = luxon.DateTime.fromISO(timeZ, {zone: utctime}).toISO({suppressMilliseconds: true});
const ukISO = luxon.DateTime.fromISO(timeZ, {zone: uktime}).toISO({suppressMilliseconds: true});
const ukzoneutc = luxon.DateTime.fromISO(timeZ, {zone: utctime}).setZone(uktime).toISO({suppressMilliseconds: true});
console.log(utcISO,' - utcISO\n'+zISO,' - zISO\n'+ukISO,' - ukISO\n'+ukzoneutc,' - uk zone from utc');
}
So to convert a UTC timestamp to a time zone, would you set to the time zone in 'fromISO' or do you prefer 'setZone', or does it matter?
references: