Domanda

Qualcuno mi può mostrare un pezzo di codice java che analizza questa data:

2009-08-05

IN QUESTA DATA GMT:

2009/217: 00: 00

====

quello che ho finora è:

       java.text.SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-dd");

       java.util.Calendar cal = Calendar.getInstance(new SimpleTimeZone(0, "GMT"));
       format.setCalendar(cal);
       java.util.Date date = format.parse(sdate);

, ma la sua non funziona

È stato utile?

Soluzione

Qui è il formato che stai cercando:

Date date = new SimpleDateFormat("yyyy-MM-dd").parse("2009-08-05");
String parsedDate = new SimpleDateFormat("yyyy/D:HH:mm").format(date);

Altri suggerimenti

format.setTimeZone(TimeZone.getTimeZone("GMT"));

Ecco come impostarlo a GMT, almeno. Non so dove hai trovato 2009/217 dal 2009-08-05

SimpleDateFormat dateFormatGmt = new SimpleDateFormat("dd:MM:yyyy HH:mm:ss");
    dateFormatGmt.setTimeZone(TimeZone.getTimeZone("GMT"));
    System.out.println(dateFormatGmt.format(new Date())+"");

Questa convertirà l'ora locale a GMT.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top