Impl: date api

main
Manish 1 year ago
parent 35e2e9b75d
commit a9ee266e34

@ -22,8 +22,19 @@ app.get("/", function (req, res) {
});
// your first API endpoint...
app.get("/api/hello", function (req, res) {
res.json({ greeting: "hello API" });
app.get("/api/:date?", (req, res) => {
if (req.params.date) {
if (Number(req.params.date)) {
const date = new Date(Number(req.params.date));
res.json({ unix: date.getTime(), utc: date.toUTCString() });
} else {
const date = new Date(req.params.date);
res.json({ unix: date.getTime(), utc: date.toUTCString() });
}
} else {
const now = new Date();
res.json({ unix: now.getTime(), utc: now.toUTCString() });
}
});
// listen for requests :)

Loading…
Cancel
Save