View source for MediaWiki:DateTimezones.js
From TwogPedia
You do not have permission to edit this page, for the following reasons:
You can view and copy the source of this page.
$(document).ready(function(){
// Function to convert UTC time to visitor's timezone
function convertUTCtoVisitorTime(utcTime) {
const userTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
const utcDate = new Date(utcTime + " UTC"); // Ensure 'utcTime' includes 'UTC' to avoid browser timezone offset
const visitorDate = utcDate.toLocaleString('en-GB', {
timeZone: userTimezone,
day: 'numeric',
month: 'short',
year: 'numeric'
}).replace(/(\w{3}) (\d{4})/, '$1, $2');
const visitorTime = utcDate.toLocaleString('en-GB', {
timeZone: userTimezone,
hour: 'numeric',
minute: 'numeric',
hour12: false
});
const timeZoneOffset = (utcDate.getTimezoneOffset() / 60) * -1
return { userTimezone, visitorDate, visitorTime, timeZoneOffset };
000
1:0
Return to MediaWiki:DateTimezones.js.
No categories