0

From an API, I'm getting back timestamps in milliseconds, as UTC. I'm using MomentJS in an Angular project (utilizing angular2-moment). First I setup:

moment.utc(dEvent.date.start)

And this displays fine, but of course, in the wrong timezone. I want to specifically display the time in US Eastern, and so found Moment Timezone. According to the docs, I should be able to convert the timezone of a Moment object with the tz method, so I tried:

moment.utc(dEvent.date.start).tz('America/New_York')

VSCode makes no complaint about this, but the Angular compiler says

__WEBPACK_IMPORTED_MODULE_6_moment__.utc(...).tz is not a function

As VSCode doesn't complain, I'm not sure where I've gone wrong. Did I screw up Angular, Typescript, or MomentJS?

Rohit
  • 3,018
  • 2
  • 29
  • 58

1 Answers1

0

That functionality is a part of Moment Timezone (https://momentjs.com/timezone/), which is a different package. Are you sure you're using that one?

You can add it like this:

npm install moment-timezone --save  

And import it like this:

import moment from 'moment-timezone';

EDIT: I just noticed in your question you said your using angular2-moment, I think you can try angular2-moment-timezone instead.

DavidX
  • 1,281
  • 11
  • 16
  • I mentioned in the question that I'm using Moment Timezone :p I didn't add the angular package because I didn't need it's extra functionality, and I did add the `@types` package of it. – Rohit Jan 27 '18 at 03:51
  • did you try utilizing `angular2-moment-timezone` ? Maybe take a look at this one https://stackoverflow.com/questions/38674835/how-to-include-moment-timezone-in-angular-2-app – DavidX Jan 27 '18 at 03:54