Fix time?

This commit is contained in:
Christopher Cookman 2025-08-20 23:10:24 -06:00
parent d04746a5d8
commit 27755fec36

View file

@ -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}`);
});