Angular 角度2+;将gmt日期时间转换为其他时区

Angular 角度2+;将gmt日期时间转换为其他时区,angular,timezone,angular2-services,timezone-offset,Angular,Timezone,Angular2 Services,Timezone Offset,在带有webpack和ts的angular 2中,转换日期字符串的最佳方式是什么,比如说'2017-07-07 12:00:11',它是GMT,通过给出偏移量'+5:30',日期时间变为'2017-07-07 17:30:11'。 我做了以下操作,但没有成功: npm install moment-timezone 在ts文件中: import * as moment from 'moment-timezone'; let setdate = moment(); // today date

在带有webpack和ts的angular 2中,转换日期字符串的最佳方式是什么,比如说
'2017-07-07 12:00:11'
,它是GMT,通过给出偏移量
'+5:30'
,日期时间变为
'2017-07-07 17:30:11'
。 我做了以下操作,但没有成功:

npm install moment-timezone
在ts文件中:

import * as moment from 'moment-timezone';

let setdate = moment(); // today date
console.log('timezone date=', setdate);

setdate.tz("GMT").format('YYYY-MM-DD HH:mm:ss');
console.log(setdate.tz("Asia/Singapore").format('YYYY-MM-DD HH:mm:ss'));
但是当我创建构建时,我得到以下错误:

Module parse failed: blah\node_modules\moment-timezone\data\packed\l
atest.json Unexpected token (2:10)
这将在angular 2或任何其他方式下工作吗???

您应该使用

setdate.tz("Europe/London").format('YYYY-MM-DD HH:mm:ss')