There are a number of errors in the code:
let day = new Date().getDay();
returns the day number (Sunday = 0, Monday = 1, etc.) not the date
let month = new Date().getMonth();
returns the month index where Jan = 0, Feb = 1, etc. so you need to add 1 to get the calendar month number.
let UkHour = new Date().getUTCHours()+ 1;
This assumes that the UK time is always UTC +1, which it isn't and also will return 24 when the hour should be 0.
The code also creates a new Date object each time, which is inefficient. To get the date and time in a particular location, use the timeZone option of the Intl.DateTimeFormat constructor, which is also available through toLocaleString.
Since localised formats of dates and times are not standardised, you might use the formatToParts method that returns the parts of a date as an array of objects, where each part has a name and value. Then you can reliably format the parts, e.g. assuming "SL" means "standard local":
// Format date as DD/MM/YY h:mm AP
function formatDate(date = new Date(), location) {
// Standard options
let opts = {
day: '2-digit',
month: '2-digit',
year: '2-digit',
hour: 'numeric',
minute: '2-digit',
second: '2-digit',
hour12: true
};
// Add timezone if supplied
if (location) {
opts.timeZone = location;
}
// Create a formatter
let f = new Intl.DateTimeFormat('en', opts);
// Get the parts
let {year, month, day, hour, minute, dayPeriod} = f.formatToParts(date).reduce(
(acc, part) => {
acc[part.type] = part.value;
return acc
}, {}
);
// Return formatted string
return `${day}-${month}-${year} ${hour}:${minute} ${dayPeriod.toUpperCase()}`;
}
console.log('UK (London): ' + formatDate(new Date(), 'Europe/London'));
console.log('Vladivostok: ' + formatDate(new Date(), 'Asia/Vladivostok'))
console.log('Local : ' + formatDate());
The format DD-MM-YY is ambiguous, not least due to the US penchant for M/D/Y but also because many places use Y-M-D, so 01-02-03 might be interpreted 3 different ways. Better to use the short month name to avoid that, e.g. 09-Aug-21. Four digit year would also be better.