convert gmt to hawaii time in javascript

To convert a GMT time to Hawaii time in JavaScript, we first need to create a Date object with the GMT timestamp. Then we can use the toLocaleString() method to format the output as Hawaii time.

Here's an example code snippet:

index.tsx
// GMT timestamp (in milliseconds)
const gmtTimestamp = 1622617314000;

// Create Date object with GMT timestamp
const gmtDate = new Date(gmtTimestamp);

// Convert to Hawaii timezone
const hawaiiDate = new Intl.DateTimeFormat('en-US', {
  timeZone: 'Pacific/Honolulu'
}).format(gmtDate);

// Output Hawaii time string
console.log(hawaiiDate);
344 chars
14 lines

In this example, we're using the Pacific/Honolulu timezone to represent Hawaii time. You can find a list of all available timezones in JavaScript here.

gistlibby LogSnag