I got this value from a server 06:21:00
but the real time in 07:21:00
which is one hour later. I think the value is in UTC and I have to change it to UTC+1. so that my code can get the time and change it to UTC+1 and one hour will be added automatically.
Process: I will get the value from Server then pass it to my javascript code and the js code will change it to UTC+1 (which one hour will be added) and show the value.
How can I convert the gotten value to UTC+1 (TimeZone Berlin)
Second Question: I wrote the new Date().toUTCString() and the result it shown in english, can I show the result in germany ? like the week days? Thanks
I believe this is what you are looking for?
It will take the timestamp from the server in UTC and convert it appropriately to a date object where you can get the time back in your local timezone.
From there, you can map the numerical representation of the day and the month index to their German day and month abbreviations and put manually build a time string.
let time = '06:21:00';
let date = new Date();
date.setUTCHours(...time.split(':'));
let days = ['Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So'];
let months = ['Jan', 'Feb', 'März', 'Apr', 'Mai', 'Juni', 'Juli', 'Aug', 'Sept', 'Okt', 'Nov', 'Dez'];
let str = `${days[date.getDay()-1]} ${months[date.getMonth()]} ${date.getDate()} ${date.getFullYear()} ${date.toTimeString()}`;
console.log(str);