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

160
Vistas
Setting date and timezone is not working in ReactJS

I have a ReactJs project where also i use jest for testing. To display the time according UK timezone, i created this function:

 const getDateTZ = dt => {
  const d = new Date(dt)
  const o = {
    hour: '2-digit',
    minute: '2-digit',
    timeZone: 'Europe/London'
  }
  return d.toLocaleTimeString('en-GB', o)
}
console.log(getDateTZ(new Date()))

This function work fine and running it i get the right time. To test this function with jest i add this:

test('It should return time', () => {
  const today = new Date()
  today.setHours(11)
  today.setMinutes(30)
  const r = getDateTZ(today)
  expect(r).toEqual('09:30')
})
Note: The difference between my location and UK is 2 hours, UK is with 2 hours behind. The test passed. So running the test alone without running all tests it passes.
ISSUE: To run all tests from entire project in my package json i added this task: "test": "TZ=UTC jest the test above fails and output this when i do npm run test:

Expected: "09:30"
Received: "11:30"

So when i run all the tests my test fails because i receive 11:30 instead of 09:30 even if the test works if i run it separately in the test file.
Question: Why i get this issue and how to get rid of it?

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