如何在Angular 2类中使用moment-timezone? [英] How to use moment-timezone in Angular 2 class?
本文介绍了如何在Angular 2类中使用moment-timezone?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在课堂上使用moment-timezone. 这是我的打字.
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"
我的导入:
import * as moment from 'moment';
import * as tz from 'moment-timezone';
我的用法:
var jun = moment("2014-06-01T12:00:00Z");
jun.tz('America/Los_Angeles').format('ha z');
我的错误:
Property 'tz' does not exist on type 'Moment'.
推荐答案
请尝试以下代码:
import * as moment from 'moment-timezone';
export class Page1 {
public setdate = moment(); // today date
constructor(){
this.setdate.tz("Asia/Singapore").format('YYYY-MM-DD HH:mm:ss');
console.log(this.setdate.tz("Asia/Singapore").format('YYYY-MM-DD HH:mm:ss'));
}
}
这篇关于如何在Angular 2类中使用moment-timezone?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文