moment / moment-timezone

Timezone support for moment.js
momentjs.com/timezone
MIT License
3.82k stars 835 forks source link

Undefined (reading 'tz) #1073

Closed A-Seraph closed 1 year ago

A-Seraph commented 1 year ago

Environment

I'm using Moment-Timezone, installed with npm on a project using Node.js. I am trying to use the code example given in the docs:

var a = moment.tz("2013-11-18 11:55", "Asia/Taipei");
console.log('a: ' + a.format()); 

I installed Moment-Timezone using the command from the docs: npm install moment-timezone --save

I have required moment-timezone at the top of the file: const { moment } = require('moment-timezone');

Issue description

The error I get is:

TypeError: Cannot read properties of undefined (reading 'tz')

Could someone tell me what I am doing wrong here please?

sslincoco commented 1 year ago

您的邮件已收到,我会尽快给您回复。

A-Seraph commented 1 year ago

I tried using AI to solve the problem. Just in case anyone else comes across this, all I had to do was remove the curly brackets. So the first line should be: const moment = require('moment-timezone');