Nvm lol, also add unix ts for my own uses
This commit is contained in:
parent
1846a8812b
commit
8eb293ca22
22
index.js
22
index.js
|
@ -83,27 +83,13 @@ app.get('/time.php', (req, res) => {
|
||||||
minute: '2-digit',
|
minute: '2-digit',
|
||||||
second: '2-digit'
|
second: '2-digit'
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
|
||||||
{
|
|
||||||
...options,
|
|
||||||
year: 'numeric',
|
|
||||||
month: '2-digit',
|
|
||||||
day: '2-digit',
|
|
||||||
hour: '2-digit',
|
|
||||||
minute: '2-digit',
|
|
||||||
second: '2-digit'
|
|
||||||
} // Old format
|
|
||||||
*/
|
|
||||||
// Example output with space-padded single digits instead of zero-padded
|
|
||||||
const spacePad = n => n.toString().padStart(2, ' ');
|
|
||||||
const parts = formatter.formatToParts(date);
|
const parts = formatter.formatToParts(date);
|
||||||
const get = type => parts.find(p => p.type === type).value;
|
const get = type => parts.find(p => p.type === type).value;
|
||||||
//const formatted = `${get('day')}${get('month')}${get('year')}${get('hour')}${get('minute')}${get('second')}`;
|
const formatted = `${get('day')}${get('month')}${get('year')}${get('hour')}${get('minute')}${get('second')}`;
|
||||||
const singleDigit = n => ' ' + (n.startsWith('0') ? n.slice(1) : n);
|
|
||||||
const formatted = `${singleDigit(get('day'))}${singleDigit(get('month'))}${singleDigit(get('year'))}${singleDigit(get('hour'))}${singleDigit(get('minute'))}${singleDigit(get('second'))}`;
|
|
||||||
const msg = fs.readFileSync(path.join(__dirname, 'msg.html'), 'utf8');
|
const msg = fs.readFileSync(path.join(__dirname, 'msg.html'), 'utf8');
|
||||||
res.send(`${formatted}<br><br>${msg}`);
|
// unix timestamp as const
|
||||||
|
const unixTimestamp = Math.floor(date.getTime() / 1000);
|
||||||
|
res.send(`${formatted}\n${unixTimestamp}<br><br>${msg}`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
res.status(400).send('Invalid timezone');
|
res.status(400).send('Invalid timezone');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue