Fix time?

This commit is contained in:
Christopher Cookman 2025-08-20 23:12:09 -06:00
parent 27755fec36
commit 7ce674243a

View file

@ -13,17 +13,15 @@ app.get('/time.php', (req, res) => {
const date = new Date();
const options = { timeZone: tz, hour12: false };
// Always pad with "0"
const pad = n => n.toString().padStart(2, '0');
// No leading zeros here
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' }));
const month = date.toLocaleString('en-GB', { ...options, month: 'numeric' });
const day = date.toLocaleString('en-GB', { ...options, day: 'numeric' });
const hour = date.toLocaleString('en-GB', { ...options, hour: 'numeric', hourCycle: 'h23' });
const minute = date.toLocaleString('en-GB', { ...options, minute: 'numeric' });
const second = date.toLocaleString('en-GB', { ...options, second: 'numeric' });
// Format: DDMMYYYYHHMMSS
// Concatenate directly: DDMMYYYYHHMMSS
const timeString = `${day}${month}${year}${hour}${minute}${second}`;
res.send(timeString);
} catch (err) {
@ -32,6 +30,7 @@ app.get('/time.php', (req, res) => {
});
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});