当我在ES6 javascript文件中使用矩时区时为什么会失败?
import moment from 'moment';
// import timezone from 'moment-timezone';
const formatTime = ({timestamp}) => {
const formattedDT = moment.tz(timestamp, 'America/Los_Angeles').format('YYYY-MM-DD HH:mm ZZ');
return formattedDT;
};
答案 0 :(得分:3)
答案 1 :(得分:0)
UPD for 2018(ES6 / React),使用npm version of moment-tz时可以使用
import moment from 'moment-timezone';
moment.tz(moment.tz.guess()).zoneAbbr();
答案 2 :(得分:0)
我在webpack 4中遇到了这个问题。
我的解决方案是获取“ moment”的正确实例。
注意:您还必须删除webpack 3中所需的.json的任何webpack加载器。
const moment = require('moment-timezone'); // import 'moment-timezone';
// once we support more regions, the timezone should be allowed to match the user's need
moment.tz.add('America/Los_Angeles|PST PDT|80 70|0101|1Lzm0 1zb0 Op0');