Fix time?
This commit is contained in:
parent
d04746a5d8
commit
27755fec36
8
index.js
8
index.js
|
@ -12,13 +12,18 @@ app.get('/time.php', (req, res) => {
|
|||
try {
|
||||
const date = new Date();
|
||||
const options = { timeZone: tz, hour12: false };
|
||||
const pad = n => n.toString().padStart(2, ' ');
|
||||
|
||||
// Always pad with "0"
|
||||
const pad = n => n.toString().padStart(2, '0');
|
||||
|
||||
const year = date.toLocaleString('en-GB', { ...options, year: 'numeric' });
|
||||
const month = pad(date.toLocaleString('en-GB', { ...options, month: '2-digit' }));
|
||||
const day = pad(date.toLocaleString('en-GB', { ...options, day: '2-digit' }));
|
||||
const hour = pad(date.toLocaleString('en-GB', { ...options, hour: '2-digit', hourCycle: 'h23' }));
|
||||
const minute = pad(date.toLocaleString('en-GB', { ...options, minute: '2-digit' }));
|
||||
const second = pad(date.toLocaleString('en-GB', { ...options, second: '2-digit' }));
|
||||
|
||||
// Format: DDMMYYYYHHMMSS
|
||||
const timeString = `${day}${month}${year}${hour}${minute}${second}`;
|
||||
res.send(timeString);
|
||||
} catch (err) {
|
||||
|
@ -26,6 +31,7 @@ app.get('/time.php', (req, res) => {
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Server is running on port ${port}`);
|
||||
});
|
Loading…
Reference in a new issue