Reputation: 1687
I'm working on using moment.js with typescript
. I ran the following commands
npm install moment-timezone --save
npm install @types/moment @types/moment-timezone --save
but for some reason in the formattime
function, moment is undefined. I'm not getting any errors from my IDE regarding my import of moment and I can see both moment
and moment-timezone
are in the npm
folder. I've been crawling through post but I'm not seeing much helpful information. Any help would be greatly appreciated
import moment from 'moment';
export class Utils {
text: string;
constructor() {
console.log('Hello Utils Component');
}
//This function take the time in MS and the timezone and coverts it
//@params time - time in milliseconds
//@params tz - the timezone
//@paramz isZoneAbbr - true if the zone abbr should be displayed
//@return - return formattedTime
public formatTime(time, tz, isZoneAbbr): string {
console.log(JSON.stringify(moment));
return "";
// var formattedTime = moment.tz(time, tz);
// if (isZoneAbbr) {
// return formattedTime.format('h:mm a z');
// }
// return formattedTime.format('h:mm a');
};
}
Upvotes: 1
Views: 2283
Reputation:
You probably have to reference as moment-timezone
and not moment
because it is not the moment
package
import * as momentTz from 'moment-timezone';
Upvotes: 2