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