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

235
Vistas
Extract local time and timezone offset information using date-fns

I have the following date string: 2022-04-16T18:31:00+02:00 and I would like to extract the local time i.e. 2022-04-16T18:31 and offset information +2:00 or 2 using date-fns.

I know I can do it with a simple string manipulation like this:

const [dateTime, offset] = "2022-04-16T18:31:00+02:00".split('+')

However, if possible, I would like to avoid string manipulation and use the library instead.

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

I can see not many people is answering here so, here is how you can get date and time in Javascript with this kind of string

const [dateTime, offset] = "2022-04-16T18:31:00+02:00".split('+');

var newDate = dateTime;

//above variable newDate will hold value that is => 2022-04-16T18:31:00

//don't use split('+'); so you can get Timezone as well 



getTimeZone =  "2022-04-16T18:31:0002:00";
var getTimeZone = getTimeZone.substring(19, getTimeZone.length-0);


console.log("timezone is "+ getTimeZone);

`````
about 4 years ago · Juan Pablo Isaza Denunciar

0

I think you should look from date-fns-tz.

Check the method (utcToZonedTime, getTimezoneOffset).

Hope this help 👋🏽

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can try something like this... [untested code]

import { format } from "date-fns";

const d = Date.parse("2022-04-16T18:31:00+02:00");
const outputDate = `${format(d, "yyyy-MM-dd'T'HH:mm")}`;

console.log(outputDate);
about 4 years ago · Juan Pablo Isaza Denunciar
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