I am trying to use moment-timezone in my class. This is my typings.
"moment": "github:DefinitelyTyped/DefinitelyTyped/moment/moment.d.ts#a1575b96ec38e916750629839d2110cb96210f89",
"moment-timezone": "github:DefinitelyTyped/DefinitelyTyped/moment-timezone/moment-timezone.d.ts#f8a90040348e83926f44e690b209769c4f88b961"
My import:
import * as moment from 'moment';
import * as tz from 'moment-timezone';
My usage:
var jun = moment("2014-06-01T12:00:00Z");
jun.tz('America/Los_Angeles').format('ha z');
My error:
Property 'tz' does not exist on type 'Moment'.
Use Typescript @types packages and import it via import * as moment from 'moment-timezone'; You can use all moment methods and member vars as moment-timezone exports them. Show activity on this post. Show activity on this post.
To use moment-timezone, you will need [email protected]+ , moment-timezone. js , and the moment-timezone data. For convenience, there are builds available on momentjs.com/timezone/ with all the zone data or a subset of the data. moment-timezone-with-data.
You can use moment.tz() to get timezone full name. It will return undefined if timezone is not set. Beside, you can use moment. format('zz') to get short timezone name.
utc(Date); By default, moment parses and displays in local time. If you want to parse or display a moment in UTC, you can use moment.
Use Typescript @types
packages and import it via import * as moment from 'moment-timezone';
You can use all moment
methods and member vars as moment-timezone
exports them.
I have a complete example using SystemJS at How to use moment-timezone in Angular2 via SystemJs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With