如何将IST timezone对象添加到Moment.js [英] How to add IST timezone object to Moment.js

查看:257
本文介绍了如何将IST timezone对象添加到Moment.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我指的是 http://momentjs.com/timezone/docs/# / use-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',//唯一标识符
abbrs:['PDT','PST'],/ /缩写
untils:[1414918800000,1425808800000],//以毫秒为单位的时间戳
偏移量:[420,480] //以分钟为单位的偏移量
}

有人可以帮助添加IST对象吗?

解决方案

最简单的方法是使用其中一个包含时区数据的文件,从 moment-timezone主页,例如 moment-timezone-2010-2020.js moment-timezone-all-years.js (或缩小的版本)。



然而,你可以添加一个单一区域,如果你喜欢。您可以在上面列出的数据文件中找到该区域的打包字符串。对于印度,整个区域定义是:

  moment.tz.add(亚洲/加尔各答| HMT BURT IST IST |  - 5R.k -6u -5u -6u | 01232 | -18LFR.k 1unn.k HB0 7zX0); 
moment.tz.link(亚洲/加尔各答|亚洲/加尔各答);

您可能需要或可能不需要链接,具体取决于您正在做什么。 >

请注意,我认为IST表示印度标准时间,而不是。这些区域当然会有不同的数据。



此外,自从印度自1942年以来一直在UTC + 5:30,您可能只想使用固定的偏移量 - 这将消除使用时刻区域的需要。只需使用 utcOffset 函数。例如,以下两项将返回印度当前的时间。

  moment()。utcOffset(+ 05:30 ).format()

  moment()。utcOffset(330).format()


I am referring to http://momentjs.com/timezone/docs/#/using-timezones/

In example, its given for below locations :

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'
]);

I am not sure of IST values as its given for :

{
    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
}

Could someone help in adding IST object to this?

解决方案

The easiest way is to just use one of the files that includes time zone data from the moment-timezone home page, such as moment-timezone-2010-2020.js or moment-timezone-all-years.js (or the minified versions).

You can however add just a single zone if you prefer. You can find the zone's packed string within the data files listed above. For India, the full zone definition is:

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");

You may or may not need the link, depending on what exactly you're doing.

Note that I assumed that by "IST" you mean India Standard Time, and not Irish Standard Time or Israel Standard Time. Those zones would have different data, of course.

Also, since India has been on UTC+5:30 since 1942, you may just wish to use a fixed offset - which would eliminate the need to use moment-timezone. Just use the utcOffset function in moment. For example, both of the following will return the current time in India.

moment().utcOffset("+05:30").format()

or

moment().utcOffset(330).format()

这篇关于如何将IST timezone对象添加到Moment.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆