Trying to set the hour for date objects regardless of time zone

One thing I realized about the setHours() function for a date object is if I try to set the hour, the hour will be set based exactly on the integer I put in. However, this is not the case in other time zones. Here’s a code snippet of what I mean, and note that I’m in the Eastern time zone:

const current = new Date()
const timeZone = "America/Los_Angeles"
current.setHours(16)

const myTimeZoneOptions = {
  hour: "numeric",
  minute: "2-digit"
}
const pacificTimeZoneOptions = {
  timeZone,
  hour: "numeric",
  minute: "2-digit"
}

console.log(current.toLocaleString("en-US", myTimeZoneOptions)) // 4:03 PM
console.log(current.toLocaleString("en-US", pacificTimeZoneOptions)) // 1:03 PM

Is there any way to make it so I get the same hour for every time zone (in this case, 4:00
PM)?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.