While fetching data from a weather API the result time zone for Indian location was 19800
, which was shift in seconds from UTC to real clock time.
timezone : 19800
I need that to real clock time. ChatGPT gave me this:
var shiftInSeconds = 19800;
var currentTimeUTC = Date.now();
var shiftedTime = currentTimeUTC + (shiftInSeconds * 1000); // Convert seconds to milliseconds
var shiftedDate = new Date(shiftedTime);
var localTime = shiftedDate.toLocaleString();
console.log("Real time:", localTime);
I got the result as
Real time: 17/05/2024, 21:27:43
The actual time now is 03:57 PM. Is there any way to get the exact local clock time ?
2
Answers
Does this work for you ?
I switched to the
toISOString()
function instead since you’re actually using UTC timeThe internal time representation is accurate already. It’s just the way you printed it.
maybe like this ?
output : "12:46:20 pm" witch is the real time for me.