我指的是 http://momentjs.com/timezone/docs/#/using-timezones/
例如,它针对以下位置给出:
moment.tz.add([
'America/Los_Angeles|PST PDT|80 70|0101|1Lzm0 1zb0 Op0',
'America/New_York|EST EDT|50 40|0101|1Lz50 1zb0 Op0'
]);
我不确定给定的 IST 值:
{
name : 'America/Los_Angeles', // the unique identifier
abbrs : ['PDT', 'PST'], // the abbreviations
untils : [1414918800000, 1425808800000], // the timestamps in milliseconds
offsets : [420, 480] // the offsets in minutes
}
有人可以帮忙添加 IST 对象吗?
最佳答案
最简单的方法是只使用其中一个包含来自 moment-timezone home page 的时区数据的文件。 ,例如 moment-timezone-2010-2020.js
或 moment-timezone-all-years.js
(或缩小版本)。
但是,如果您愿意,您可以只添加一个区域。您可以在上面列出的数据文件中找到该区域的打包字符串。对于印度,完整的区域定义是:
moment.tz.add("Asia/Calcutta|HMT BURT IST IST|-5R.k -6u -5u -6u|01232|-18LFR.k 1unn.k HB0 7zX0");
moment.tz.link("Asia/Calcutta|Asia/Kolkata");
您可能需要也可能不需要该链接,具体取决于您在做什么。
请注意,我假设“IST”指的是印度标准时间,而不是 Irish Standard Time or Israel Standard Time .当然,这些区域会有不同的数据。
此外,由于印度自 1942 年以来一直使用 UTC+5:30,您可能只希望使用固定偏移量 - 这样就无需使用时刻时区。只需立即使用 utcOffset
函数即可。例如,以下两个都将返回印度的当前时间。
moment().utcOffset("+05:30").format()
或
moment().utcOffset(330).format()
关于javascript - 如何将 IST 时区对象添加到 Moment.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32355297/