i have a dropdown to select timezone in UI.
that dropdown data taken from windows timezone settings dropdown list
If logged user in selected some timezone, i have to display all datetime fields according to selected timezone format with DST.
Typescript ts code
import * as moment from 'moment';
import * as momenttimezone from 'moment-timezone';
private ConvertServerTimezoneToClient(dateTime: string, dateFormat: string, timeFormat: string, timezoneFormat: string, isDstzone: string) {
timeFormat = timeFormat.toString().indexOf('tt') > -1 ? timeFormat.replace('tt', 'a') : timeFormat;
var convertedTime = '';
if (timezoneFormat && timezoneFormat != '' && timezoneFormat != "null") {
if (isDstzone == 'true') {
momenttimezone.tz.add(''); // need to map
momenttimezone.tz.link(''); // need to map
var zoneName = ''; // need to map
var isDstDate = momenttimezone.tz(new Date(dateTime), zoneName).isDST();
if (isDstDate) {
convertedTime = moment(dateTime).zone(timezoneFormat).add(1, 'hours').format(dateFormat + ' ' + timeFormat);
} else {
convertedTime = moment(dateTime).zone(timezoneFormat).format(dateFormat + ' ' + timeFormat);
}
}
else {
convertedTime = moment(dateTime).zone(timezoneFormat).format(dateFormat + ' ' + timeFormat);
}
}
return convertedTime
}
Moment js have more timezone formats https://github.com/moment/moment-timezone/blob/develop/data/packed/latest.json
How to map windows timezone to moment timezone. UI base code is with aurelia typescript. Need help.