TypeError: moment().tz is not a function

后端 未结 5 997
Happy的楠姐
Happy的楠姐 2021-01-01 08:26

When testing using jasmine, I am getting this error.

TypeError: moment.tz is not a function

My code that I try to test is

l         


        
5条回答
  •  难免孤独
    2021-01-01 08:47

    Moment should be a function call. So use let myDate = moment().tz(...)

    See https://momentjs.com/timezone/docs/ for more details.

    EDIT

    You should also ensure that you are including the timezone extension to the moment library either through the correct npm install and require (for Node) or the correct script tags (for general browser usage). See the linked documents for the libraries/scripts to include.

    SECOND EDIT

    Should anyone have scrolled this far on a question with a +120 accepted answer:

    The suggestion that moment was a function and requires brackets refers to the un-edited version of the posted question which had the syntax

    let myDate = moment.tz(undefined, vm.timeZone).format('YYYY-MM-DD');

提交回复
热议问题