Tag: utc

Heroku – NodeJS无法将date转换为UTC

我需要在我的本地时间创build一个date,并将其转换为UTC保存在数据库中。 我在我的本地环境和Heorku有下面的代码: // node dateTest.js var moment = require('moment-timezone'); var timeZone = 'Pacific/Auckland'; var date = moment('20160101235959', 'YYYYMMDDHHmmss').tz(timeZone); var UTCdate = date.utc().toISOString(); console.log(UTCdate); 当我在本地运行时,我得到: 2016-01-01T10:59:59.000Z UTC时间是正确的。 但是当我在Heorku实例上运行时,我得到: 2016-01-01T23:59:59.000Z 最后是Z字面的date。 为什么会这样呢? 我无法弄清楚。 🙁 NodeJS v5.1.0

客户端本地时间服务器上

我的客户端和服务器在不同的时区,数据库中的所有date都以UTC格式存储。 我们希望在客户端时间而不是UTC时间在服务器上生成报告。 当创buildnew Date(UTCDate)将UTC转换为服务器date时间,而不是带时区偏移量的客户端。

NodeJS会话variables不会粘住

我有一个nodejs和连接的问题,并没有保持请求之间的会话variables的事实。 现在我不想用数据库来存储我的会话。 我只想使用MemoryStore。 我的服务器: var server = connect() .use(connect.cookieParser('justmeknowsthis')) .use(connect.session({ cookie: { maxAge: config.data.sessionTimeout /* 1800000 */ }})) .use(auth.authorize) .use(routes.routes) .use(function(req, res, next) { utils.data.returnJsonError(res, 404, true, { message: 'Call not supported' }); }); 我正在设置像这样的会话variables: req.session.auth = true; req.session.username = data.username; 在发现了一些关于这个问题的更多信息之后,我注意到,如果我只是增加超时时间,那么可能是因为它开始工作时区。 从我过去的使用ASP.Net的经验,我从来没有遇到过这个问题,因为它似乎并不关心。 我怎样才能解决这个问题?

moment.js – UTC不工作,因为我期望它

在节点控制台中testing: var moment = require('moment'); // create a new Date-Object var now = new Date(2013, 02, 28, 11, 11, 11); // create the native timestamp var native = Date.UTC(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours(), now.getMinutes(), now.getSeconds()); // create the timestamp with moment var withMoment = moment.utc(now).valueOf() // it doesnt matter if i use moment(now).utc().valueOf() or moment().utc(now).valueOf() // […]