具有瞬间时区的Ionic 2 Moment JS

时间:2017-04-07 20:11:45

标签: angular typescript ionic2 momentjs typescript-typings

我正致力于使用moment.js with typescript。我运行了以下命令

npm install moment-timezone --save
npm install @types/moment @types/moment-timezone --save

但由于formattime函数的某些原因,时刻未定义。我的IDE在导入时没有收到任何错误,我可以看到momentmoment-timezone都在npm文件夹中。我一直在浏览帖子,但我没有看到太多有用的信息。任何帮助将不胜感激

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');
    };
}

1 个答案:

答案 0 :(得分:2)

您可能需要引用moment-timezone而不是moment,因为它不是moment

import * as momentTz from 'moment-timezone';
相关问题