411 REFERENCE · Wikibooks
JavaScript/Dates/Exercises
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
1. You can show the offset between your timezone and UTC by using getTimezoneOffset(). Show this offset.
100% "use strict";
const ts_1 = new Date();
alert(ts_1.getTimezoneOffset());
2. Show the offset again, but don't use getTimezoneOffset(). Instead, work with Date.now() and Date.UTC().
100% "use strict";
// Use an arbitrary timestamp, i.e., the first second of our century.
// a) in your timezone
const ts_2 = new Date(2000, 0, 1);
alert('Numerical value: ' + ts_2.valueOf());
alert(new Date(ts_2));
// b) in UTC
const ts_3 = Date.UTC(2000, 0, 1);
alert('Numerical value: ' + ts_3.valueOf());
alert(new Date(ts_3));
// the difference
const minutes = (ts_2 - ts_3) / 60000;
alert(minutes);