Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

259
Visualizações
How would I take a start/end dates user input, and convert it to US Pacific time, in ISO format?

I need to work a date object thru a specific set of circumstances.

  1. user is inputting a daterange, from/to.
  2. each date needs to be converted toISOString() because that's how it is in the DB.
  3. client wants the dateranges to hard convert to US Pacific time.

So when the user chooses from/to dates, the app is makes their chosen dates in US Pacific timezone, and then searches the db using ISO formatted dates.

I have this SE Post which gets me the timezone conversion, but in a non-iso format. Any attempts at deriving toISOString() molests the object right back to the device timezone.

I'm trying dayjs(), but it winds up being a bunch of extra steps, only to have the end result be molested to the device timezone.

How can I get the above series of events to unfold in the necessary order?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Here is how you do it with dayjs

const dayjs = require("dayjs");
const utc = require("dayjs/plugin/utc");
const timezone = require("dayjs/plugin/timezone");

dayjs.extend(utc);
dayjs.extend(timezone);
let t = dayjs()
  .tz("America/Los_Angeles")
  .utc(true)
  .toISOString();

console.log(t);

Here is a list of all timezones https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

I personally live in europe, but when i execute this script it shows me the time in los angeles in ISO format

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda