Skip to content

Commit

Permalink
fix: fix datetime miscalculations
Browse files Browse the repository at this point in the history
  • Loading branch information
MrGriefs committed Sep 28, 2021
1 parent 39b8751 commit 3d52894
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions index.html
Expand Up @@ -20,24 +20,18 @@
var serial = "6039"+s;

setInterval(() => {
let timedate;
if (utc) timedate = new Date();
else {
const now = new Date();
now.setTime(now.getTime() + now.getTimezoneOffset() * 6e4);
if (
now.getTimezoneOffset() <
Math.max(
new Date(now.getFullYear(), 0, 1).getTimezoneOffset(),
now.getTimezoneOffset()
)
) setoffset = offset + 1;
else setoffset = offset;
timedate = new Date(now.getTime()+(setoffset * 36e5));
}

const iso = timedate.toISOString();
$("#date").text(`${iso.substring(0, 10)} ${iso.substring(11, 19)} ${offset > 0 ? '-' : '+'}${offset.toString().padEnd(3, '0').padStart(4, '0')}`);
const now = new Date();
let offset = now.getTimezoneOffset() / -60;
now.setTime(now.getTime() + offset * 60);
if (
now.getTimezoneOffset() <
Math.max(
new Date(now.getFullYear(), 0, 1).getTimezoneOffset(),
new Date(now.getFullYear(), 6, 1).getTimezoneOffset()
)
) offset += 1;
const iso = new Date(now.getTime() + (offset * 36e5)).toISOString();
$("#date").text(`${iso.substring(0, 10)} ${iso.substring(11, 19)} ${offset < 0 ? '-' : '+'}${Math.abs(offset).toString().padEnd(3, '0').padStart(4, '0')}`);
}, 1e3)

$(() => {
Expand Down

0 comments on commit 3d52894

Please sign in to comment.