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

276
Visualizações
How to use java.time.ZonedDateTime & format.DateTimeFormatter without GMT?

Doing the following:

val zonedFormatter: DateTimeFormatter = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm z")

ZonedDateTime.from(zonedFormatter.parse("31.07.2020 14:15 GMT"))

Gives me:

"displayDate": "2020-07-31T14:15:00Z[GMT]"

I want it without the [GMT]:

"displayDate": "2020-07-31T14:15:00Z"
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can use DateTimeFormatter.ISO_OFFSET_DATE_TIME to format the parsed ZonedDateTime. However, if you are expecting the date-time always in UTC, I recommend you convert the parsed ZonedDateTime into Instant.

Demo:

import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

public class Main {
    public static void main(String[] args) {
        DateTimeFormatter dtfInput = DateTimeFormatter.ofPattern("dd.MM.uuuu HH:mm z", Locale.ENGLISH);

        ZonedDateTime zdt = ZonedDateTime.from(dtfInput.parse("31.07.2020 14:15 GMT"));
        System.out.println(zdt.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME));

        System.out.println(zdt.toInstant());
    }
}

Output:

2020-07-31T14:15:00Z
2020-07-31T14:15:00Z

ONLINE DEMO

Learn more about the modern Date-Time API* from Trail: Date Time. Check this answer and this answer to learn how to use java.time API with JDBC.


* If you are working for an Android project and your Android API level is still not compliant with Java-8, check Java 8+ APIs available through desugaring. Note that Android 8.0 Oreo already provides support for java.time.

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