From 895095078921905165331de79c5b5daddabc3046 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Thu, 21 Aug 2025 06:12:24 -0600 Subject: [PATCH] Just gonna go back to basics lol --- index.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index f931baf..8f5f29a 100644 --- a/index.js +++ b/index.js @@ -9,22 +9,23 @@ app.get('/', (req, res) => { app.get('/time.php', (req, res) => { const tz = req.query.zone || 'UTC'; + const date = new Date(); try { - const date = new Date(); const options = { timeZone: tz, hour12: false }; - - // No leading zeros here - const year = date.toLocaleString('en-GB', { ...options, year: 'numeric' }); - 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' }); - - // Concatenate directly: DDMMYYYYHHMMSS - const timeString = `${day}${month}${year}${hour}${minute}${second}`; - res.send(timeString); - } catch (err) { + const formatter = new Intl.DateTimeFormat('en-GB', { + ...options, + year: 'numeric', + month: '2-digit', + day: '2-digit', + hour: '2-digit', + minute: '2-digit', + second: '2-digit' + }); + const parts = formatter.formatToParts(date); + const get = type => parts.find(p => p.type === type).value; + const formatted = `${get('day')}${get('month')}${get('year')}${get('hour')}${get('minute')}${get('second')}`; + res.send(formatted); + } catch (e) { res.status(400).send('Invalid timezone'); } });