Impl: date api

This commit is contained in:
Manish 2023-03-28 02:25:02 +11:00
parent 35e2e9b75d
commit a9ee266e34

View File

@ -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 :)