So, I’m doing the microservice project where I have to get unix date timestamp . No test cases are being passed…
app.get("/api/timestamp/:date_string", function(req, res) {
// {"unix":1450137600000,"utc":"Tue, 15 Dec 2015 00:00:00 GMT"}
var date = req.query.date_string;
console.log(date);
const epoch = parseInt(date, 10);
console.log("Hello");
if (isNaN(epoch)) {
console.log("isNan");
var dateObject = new Date(date);
if (dateObject.toString() === "Invalid Date") {
res.json({ error: "Invalid Date" });
} else {
var returnObject = {
unix: dateObject.valueOf(),
utc: dateObject.toUTCString()
};
res.json(returnObject);
}
} else {
// if the returned is a number then convert into epoch and show the result..
console.log("is else");
var returnObject = { unix: epoch, utc: new Date(epoch).toUTCString() };
res.json(returnObject);
}
});
when I try to enter some query parameter in the URL like date_string=1450137600000
the unix timestamp changes to 1586061823000.
and that’s the reason why I think it is happening. How should I resolve this.
Thanks