How to use moment-timezone in Angular 2 class?

前端 未结 4 2041
梦毁少年i
梦毁少年i 2021-02-07 09:24

I am trying to use moment-timezone in my class. This is my typings.

\"moment\": \"github:DefinitelyTyped/DefinitelyTyped/moment/moment.d.ts#a1575b96ec38e91675062         


        
4条回答
  •  伪装坚强ぢ
    2021-02-07 10:08

    I had the same issue and solved it this way:

    Typings (ambientDependencies):

    "moment": "registry:dt/moment#2.8.0+20160316155526",
    "moment-timezone": "github:DefinitelyTyped/DefinitelyTyped/moment-timezone/moment-timezone.d.ts#f8a90040348e83926f44e690b209769c4f88b961"
    

    Import:

    import * as moment from 'moment';
    import 'moment-timezone'
    

    Usage:

    moment("2014-06-01T12:00:00Z")
      .tz('America/Los_Angeles')
      .format('ha z');
    

    So, basically I'm doing .tz() function on moment imported object (which in fact does not exist), but the import of moment-timezone extends it with additional functions.

    I'm also using systemjs-plugin-json to properly load json object with timezone definitions inside moment-timezone library.

    I hope this helps.

提交回复
热议问题