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

158
Visualizações
get timezone from an instance of a dayjs object?

I have a util method that takes date input and converts it to dayjs instance with timezone conversion is optional.

import dayjs from 'dayjs';
import timezone from 'dayjs/plugin/timezone';
import utc from 'dayjs/plugin/utc';

const convertDateToLocalFormat= (date = dayjs(), isTimezoneConvesrionRequired = true)=>{
  
  dayjs.extend(utc);
  dayjs.extend(timezone);
  if(isTimezoneConvesrionRequired){
   const tZone = dayjs.tz().guess();
   return dayjs(date).tz(tZone);
  }
  return dayjs(date);

}

** The problem: ** Now if I pass an instance of daysjs object to this function, for which already timezone is applied(in the first iteration), I am getting a date which has two times timezone applied. For example, I am Pacific time zone(browser timezone, let's say 9 am, Feb 5th, 2022). My target time zone is India (I am getting this timezone from my database). So Instead of getting 10.30 pm, Feb 5th, 2022 I am getting 12 am, Feb 6th, 2022.

** My approach: ** If there is a way to get timezone info from a dayjs object, I can check whether the timezone is the same. Something like this.

const instanceTimeZone = date.getTimeZoneInfo() // assuming date is already an instance 
                                               // of dayjs and getTimeZoneInfo() is what 
                                               // I am looking for, some util kind of 
                                               // method
if(isTimezoneConvesrionRequired && instanceTimeZone !== dayjs.tz().guess() ){
   const tZone = dayjs.tz().guess();
   return dayjs(date).tz(tZone);
  }
about 4 years ago · Juan Pablo Isaza
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