Impl: date api
This commit is contained in:
parent
35e2e9b75d
commit
a9ee266e34
15
index.js
15
index.js
@ -22,8 +22,19 @@ app.get("/", function (req, res) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// your first API endpoint...
|
// your first API endpoint...
|
||||||
app.get("/api/hello", function (req, res) {
|
app.get("/api/:date?", (req, res) => {
|
||||||
res.json({ greeting: "hello API" });
|
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 :)
|
// listen for requests :)
|
||||||
|
Loading…
Reference in New Issue
Block a user