const express = require('express'); const app = express(); const port = process.env.SERVER_PORT || 3000; app.get('/', (req, res) => { res.send('Hello, world!'); }); app.get('/time.php', (req, res) => { const tz = req.query.zone || 'UTC'; try { const date = new Date(); const options = { timeZone: tz, hour12: false }; 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' })); const timeString = `${day}${month}${year}${hour}${minute}${second}`; res.send(timeString); } catch (err) { res.status(400).send('Invalid timezone'); } }); app.listen(port, () => { console.log(`Server is running on port ${port}`); });