We are trying to calculate the client-server time offset by using EPOC value sent from backend API, when doing that I am running into an issue in local browser/client side.
when i get EPOC from backend API I.e. serverEpocValue = 1653107370620 and trying to compare it with the local epoc value the difference is not 6 hours as I expected, it's around few milliseconds difference, why is epoc value close to local time instead of the server time?
const serverdate = new Date(1653107370620)
serverDate = Sat May 21 2022 09:59:30 GMT+0530 (locale browser date and time)
How do we get the server UTC time using epoc to calculate the offset in the client side?
The time through facilities Date.now() will always be in milliseconds from Jan 1 1970 UTC and does not consider timezones. If you need to get the timezone offset you should use something like Date.getTimezoneOffset
which will return the offset in minutes.