简体   繁体   English

具有Moment TimeZones的Ionic 2 Moment JS

[英]Ionic 2 Moment JS with Moment TimeZones

I'm working on using moment.js with typescript . 我正在使用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. 但由于formattime函数中的某些原因,矩未定义。 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. 我没有从我的IDE得到任何错误关于我的时刻的进口,我可以看到这两个momentmoment-timezone是在npm文件夹中。 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');
    };
}

您可能必须引用的是moment-timezone而不是moment因为它不是moment

import * as momentTz from 'moment-timezone';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM