Basic Node and Express - Chain Middleware to Create a Time Server(2)

Basic Node and Express - Chain Middleware to Create a Time Server(2)
0

#1

I’m getting:
the returned time is not between ± 20 secs from now;
I noticed that the new Date() returns GMT -0, which is not my browser time and for that reason the test might fail,
I read how to change it and managed to sync it as you can see below but it still won’t work.
Please advise…


req.time =  new Date(new Date().toString()+"-0300").toGMTString();
  console.log(req.time);
next();
},
        function(req, res) {
  res.send({time: req.time});
})

#2

new Date() Object automatically grabs current time based on your timezone. Therefore there is no need to add any string numbers for it. Go head and simply create a new Date. Then strigify it and save it in req.time.

req.time = new Date().toString();


#3

it didn’t work at the first place when i used just “new Date()” , that’s the reason i started to complex everything