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;
Here's one way to do this, using Date#toLocaleString():
(target timezone name can be looked up here: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)
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
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP