【发布时间】:2018-07-27 23:41:12
【问题描述】:
我一直在尝试找出 moment-timezone.js 的问题。我似乎无法将时间戳从 UTC 转换为 PST
我使用的辅助函数是 timeInTimeZone。请原谅可怕的变量名。
非常感谢调试问题的任何帮助
Template.home.helpers({
timezone: function() {
return Template.instance().timezone.get();
},
timeInTimeZone : function(){
let time = moment( this.createdAt ),
format = 'dddd, MMMM Do YYYY h:mm a';
var timezone = Template.instance().timezone.get();
console.log(time.format( format )); //works
console.log(timezone); //works
var editedTime = time.tz( timezone ).format( format ); //breaks
console.log(editedTime);
return editedTime;
}
});
我使用这个时得到的日志如下:
2018 年 2 月 17 日星期六上午 1:11 home.js:141:5 美国/温哥华 home.js:142:5 模板助手中的异常:timeInTimeZone@http://localhost:3000/app/client/views/pages/home.js?hash=f7d8b7711106080a4d6fbb1d2089cf344f59223d:143:22 bindDataContext/http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:3051:14 Blaze._wrapCatchingExceptions/http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:1715:14 wrapHelper/http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:3103:14 Template._withTemplateInstanceFunc@http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:3744:12 wrapHelper/http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:3102:12 空格键.call@http://localhost:3000/packages/spacebars.js?hash=547cf8e466d1d52603d19bd5f48fb5df184fd237:172:12 空格键.mustacheImpl@http://localhost:3000/packages/spacebars.js?hash=547cf8e466d1d52603d19bd5f48fb5df184fd237:106:10 空格键.mustache@http://localhost:3000/packages/spacebars.js?hash=547cf8e466d1d52603d19bd5f48fb5df184fd237:110:16 Template.homehttp://localhost:3000/app/client/views/pages/template.home.js?hash=be956f7036145947c4a904d9c42627576e740dd1:82:14 doRender@http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:2086:20 viewAutorun/http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:1934:18 Template._withTemplateInstanceFunc@http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:3744:12 查看自动运行/http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:1932:14 Blaze._withCurrentView@http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:2271:12 查看自动运行@http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:1931:12 Tracker.Computation.prototype._compute@http://localhost:3000/packages/tracker.js?hash=0e8b5c18d543a28ce43b2f183c26b49ee62196af:339:5 Tracker.Computation.prototype._recompute@http://localhost:3000/packages/tracker.js?hash=0e8b5c18d543a28ce43b2f183c26b49ee62196af:358:9 Tracker._runFlush@http://localhost:3000/packages/tracker.js?hash=0e8b5c18d543a28ce43b2f183c26b49ee62196af:532:9 onGlobalMessage@http://localhost:3000/packages/meteor.js?hash=b0f12795c8cc1423b5850502871996903f947ed5:448:11
我尝试使用 meteor npm 和 meteor add 重新安装 moment 和 momnet-timezone
我知道这与 time.tz() 有关,传递给它的是以下America/Vancouver
【问题讨论】:
-
home.js 的第 143 行发生了什么?我猜你在哪里评论了休息时间。
标签: javascript node.js meteor momentjs