C# 如何将windows时区转换为即时js时区
我有一个下拉菜单来选择UI中的时区。 该下拉列表数据取自windows时区设置下拉列表 如果登录用户选择了某个时区,我必须使用DST根据所选时区格式显示所有datetime字段 我的桌子结构是 类型脚本ts代码C# 如何将windows时区转换为即时js时区,c#,timezone,momentjs,aurelia,moment-timezone,C#,Timezone,Momentjs,Aurelia,Moment Timezone,我有一个下拉菜单来选择UI中的时区。 该下拉列表数据取自windows时区设置下拉列表 如果登录用户选择了某个时区,我必须使用DST根据所选时区格式显示所有datetime字段 我的桌子结构是 类型脚本ts代码 import * as moment from 'moment'; import * as momenttimezone from 'moment-timezone'; private ConvertServerTimezoneToClient(dateTime: string,
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
}
现在js有更多的时区格式
如何将windows时区映射到时刻时区。UI基本代码使用aurelia typescript。需要帮助。没有快速或简单的方法可以做到这一点。Momentjs不支持它,也不打算这样做——这与您应该在服务器上而不是在客户机上这样做的原因相同。如果您需要.NET代码中Windows格式的时区 如果出于某种原因,您仍然坚持对客户执行此操作,您可以使用。解析该文件,然后使用它进行映射
除此之外,我强烈建议使用UNIX时间戳而不是字符串。传递一个明确的数字要比跟踪并正确解析字符串时间戳容易得多,因为每个体面的DateTime库都知道如何正确转换。如果您在服务器端代码中运行.NET,服务器端处理这个问题会更好,这里显示的代码有几个bug。您不应该尝试手动为DST添加一小时。瞬间时区拥有所有内置功能。另外,除了TT to A之外,你可能还有其他一些悬念。