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

751
Vistas
remove the local timezone from a date in javascript?

I was wondering if I can remove the timezone from the date using javascript? I get the datetime on a json format, now I want to set it back but it returns more info of what I actually want/need.

What I have now is:

var d = new Date();
d.setTime(1432851021000);
document.write(d);

and the output is something like this:

Thu May 28 2015 16:10:21 GMT-0600 (CST)

Id like to show only until the hour, and remove GMT-0600 (CST).

I know javascript takes that depending on the current user's timezone, which is a problem, because the information could be saved on different countries.

I am trying to avoid to create the format using something like:

d.date() + "/" + d.month()...etc

Is there a better solution for this?

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

I believe d.toDateString() will output the format you're looking for.

var d = new Date();
d.setTime(1432851021000);
d.toDateString(); // outputs to "Thu May 28 2015"
d.toGMTString(); //outputs to "Thu, 28 May 2015 22:10:21 GMT"

Or even d.toLocaleString() "5/28/2015, 6:10:21 PM"

There are lots of methods available to Date()

over 4 years ago · Santiago Trujillo Denunciar

0

Since the part you want will always has fixed length you can use:

d.toString().slice(0, 24)

jsfiddle

over 4 years ago · Santiago Trujillo Denunciar

0

Using moment

moment().utcOffset(0, true).format()

From Javascript Date

var date = new Date();
Tue Sep 06 2021 00:00:00 GMT+0200

var isoDate = date.toISOString()
'2021-09-05T22:00:00.000Z'

var clearUTCDate = moment(date).utcOffset(0, true).format() 
'2021-09-06T00:00:00Z'
over 4 years ago · Santiago Trujillo 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