Reputation: 77
I'm having a very strange issue whereby getting the time value from my HTTP POST req in express always result in NaN if I'm trying to convert it to ISO String or even Date object.
Here is my URL request: http://localhost:3000/sensor/reading/update?value=33.5&time=1430217238000
update.js
var express = require('express');
var router = express.Router();
var moment = require('moment');
router.post('/', function(req, res, next) {
var time = moment(req.query.time);
}
I am sure that the req.query.time is valid since I can see the exact value in console.log(req.query.time). Even var time = new Date(req.query.time) also result in invalid date.
Totally lost of thoughts here :(
Upvotes: 2
Views: 1245
Reputation: 318182
You're getting a string, and you probably want an integer
var time = new Date( parseInt( req.query.time, 10) );
Upvotes: 1