Skip to content

Instantly share code, notes, and snippets.

@nbdd0121
Created September 28, 2018 21:55
Show Gist options
  • Save nbdd0121/da7c140af7afab74d7763f1a8fbae114 to your computer and use it in GitHub Desktop.
Save nbdd0121/da7c140af7afab74d7763f1a8fbae114 to your computer and use it in GitHub Desktop.
Bilibili Timeline Timezone Fix
let timezoneOffset = 8 * 60; // in minutes
function timeshift(date) {
return new Date(+date + timezoneOffset * 60000);
}
// Seconds and Milliseconds are always same as timezone offset is always multiple of 0.5
for (let name of ['Date', 'Day', 'FullYear', 'Hours', 'Minutes', 'Month']) {
Date.prototype['get' + name] = function () {
return timeshift(this)['getUTC' + name]();
}
if (name === 'Day') continue;
Date.prototype['set' + name] = function (arg) {
let date = timeshift(this);
date['setUTC' + name](arg);
this.setTime(+date - timezoneOffset * 60000);
}
}
Date.prototype.getTimezoneOffset = function () {
return -timezoneOffset;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment