PDA

View Full Version : [Java][SimpleDateFormat ]


melarco
06-03-2008, 19:57
salve sto provando ad utilizzare questo metodo per convertire la data che do in input al metodo "wed Mar 05 10:02.02 CET 2008" per trasformarla in dd/MM/yyyy
ma viene sempre sollevata l' eccezione .MI dice Unparseable date:...

//passo al metodo dateOld ="wed Mar 05 10:02.02 CET 2008"

sapreste aiutarmi??!!:muro:
grazie
public String formatData(String dateOld) {



SimpleDateFormat dateStandard=null ;

try {

dateStandard =
new SimpleDateFormat("EEE MMM dd HH:mm:ss 'CET' yyyy", Locale.ITALIAN).parse(dateOld);

System.out.printl("DATESTANDARD"+dateStandard);

} catch (ParseException e) {
System.out.println("errore");
e.printStackTrace();
}

String dateFormatted = new SimpleDateFormat("dd/MM/yyyy").format(dateStandard);

return dateFormatted;
}

andbin
06-03-2008, 20:51
Cosė č corretto:

DateFormat df = new SimpleDateFormat ("EEE MMM dd HH:mm:ss Z yyyy", Locale.ENGLISH);
Date d = df.parse ("wed Mar 05 10:02:02 CET 2008");
Nel tuo codice avevi usato Locale.ITALIAN (ma wed non č certo italiano!) e poi nella stringa di input hai messo un punto 10:02.02

melarco
07-03-2008, 19:22
grazie mille funziona!!!!