To convert Eastern Time to Pacific Time in JavaScript, you can use the Moment.js library. Here's how you can do it:
index.tsx346 chars11 lines
In this code, we first set the date and time in Eastern Time using the moment.tz()
function. We pass in the date string as the first argument and the timezone string (in this case, "America/New_York"
) as the second argument.
We then clone this moment object and convert it to Pacific Time using the tz()
function again with the timezone string "America/Los_Angeles"
.
Finally, we format the resulting moment object as a string using the format()
function and output the formatted date and time to the console.
Note that you'll need to include the Moment.js library in your project and import it into your JavaScript file before you can use it.
gistlibby LogSnag