0
我有一個位於西海岸的客戶端,但希望看到基於東海岸時間(美國/紐約)的信息。使用WallTime.js進行js時區轉換,但出現錯誤
我試圖使用WallTime庫:https://github.com/sproutsocial/walltime-js
define(function(require) {
var _ = require('underscore'),
Backbone = require('backbone'),
WallTime = require('walltime');
require('backbone.relational');
require('walltime-data');
var DateRange = Backbone.RelationalModel.extend({
initialize: function(opts) {
var self = this,
type = (opts && opts.type) || "today";
if(type == "custom") {
var undef = _.isUndefined(opts.start) && _.isUndefined(opts.end);
if(undef)
throw "'start' and/or 'end' date not present in options for type: custom";
}
function getNycDate(date){
var someUTCDate = new Date(date.getTime()),
nycWallTime = WallTime.UTCToWallTime(someUTCDate, "America/New_York");
return nycWallTime;
}
function setup() {
var now = getNycDate(new Date());
}
}
}
}
當試圖計算我收到以下錯誤walltime: 未捕獲的錯誤:設置時區
之前必須調用初始化規則和區
我不認爲你正在正確加載'walltime-data.js'。您似乎正在使用RequireJS。你是否將'walltime'和'walltime-data'設置爲模塊?您是否將'walltime-data'設置爲'wall-time'的依賴項?請參閱[RequireJS文檔](http://requirejs.org/docs/api.html#funcmodule)。 – 2013-02-27 21:52:00
@Matt Johnson:這些'require's是CommonJS模塊,而不是'RequireJS'支持的AMD格式(比較這裏:http://blog.millermedeiros.com/amd-is-better-for-the-web-than- commonjs-modules /) – kryger 2013-02-27 22:13:17