javascript get Pacific Timezone

Stack Overflow Asked on December 7, 2020

i don’t live in the pacific area and i am looking for a way to get the current day in the pacific area as my midnight does not match pacific midnight, how to do?

Current code

//how to set this to Pacific Time?
var timezone = new Date();

//get the current day
var day = timezone.getDate();

//use the day           
var row_for_day = day+3;

One Answer

Here's one way to do this, using Date#toLocaleString():

(target timezone name can be looked up here:

const target = "America/Los_Angeles";

const laDate = +new Date().toLocaleString("en-US", {
  timeZone: target,  // conversion here
  day: "numeric"     // return day only

console.log("date in LA:", laDate);

I was looking for existing answers but wasn't able to find a good, current, concise fit. Point one out and I will remove this.

Answered by Chris G on December 7, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP