app.get("/api/timestamp", (req, res) => {
res.json({ unix: Date.now(), utc: Date() });
});
app.get("/api/timestamp/:date_string", (req, res) => {
let dateString = req.params.date_string;
//A 4 digit number is a valid ISO-8601 for the beginning of that year
//5 digits or more must be a unix time, until we reach a year 10,000 problem
if (/\d{5,}/.test(dateString)) {
const dateInt = parseInt(dateString);
//Date regards numbers as unix timestamps, strings are processed differently
res.json({ unix: dateInt, utc: new Date(dateInt).toUTCString() });
} else {
let dateObject = new Date(dateString);
if (dateObject.toString() === "Invalid Date") {
res.json({ error: "Invalid Date" });
} else {
res.json({ unix: dateObject.valueOf(), utc: dateObject.toUTCString() });
}
}
});
this is my code
this is the output
{"unix":1451001600000,"utc":"Fri, 25 Dec 2015 00:00:00 GMT"}
when i pass my peoject link in solution link then Your project can handle dates that can be successfully parsed by new Date(date_string) again i got this error
Please update GitHub with your latest code. Or, better yet, clone your project to a service like Replit or CodeSandbox, or Glitch, then you can share a link to your code.