Find out UTC minus random local time
Updated: Dec 15, 2022
There are times when you have a specific time in UTC. And you need to know how much ahead or behind your local time is in comparison to UTC. To know that you can simply use date.timezoneOffset that will output the number of minutes your time is ahead or behind as compared to the time in UTC.
var timeInUTC = Date.UTC(2019,6,10,13,0,0); var d:Date = new Date(); trace(d.timezoneOffset/60); //converting to hours from minutes
But what if you need to know how much a random local time is ahead or behind the time in UTC. This is the way out.
var d:Date = new Date(); var localTimeInUTC =Date.UTC(d.fullYearUTC,d.monthUTC,d.dateUTC,d.hoursUTC,d.minutesUTC,d.secondsUTC); var timeDifferenceInHours = (timeInUTC-localTimeInUTC)/(3600*1000)