Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

159
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda