Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

749
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda