Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

92
Vistas
Formatted date as String converted to date wrong

I am trying to store date in DB using the current timezone. I have used library date-fns-tz When I convert the date as a string is okay, but when I want to create that string as a Date it is still a problem.

    const date = new Date();
const date_string = formatInTimeZone(
  date,
  "Europe/Rome",
  "yyyy-MM-dd HH:mm:ss"
);

console.log(date_string); //2022-04-16 11:46:28  (Right time)
const current_date = new Date(date_string); // 2022-04-16T09:46:28.000Z   (Converted to 2h back)
7 months ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos