Re: Fehler im Java melden?



Michael Hüttermann schrieb:
Michael Stricker wrote:

Hallo Leute,

wie melde ich den an Sun einen Fehler über Java?


Was haste denn gefunden? :)

Die Datumsfunktion mit SimpleDateFormat arbeitet bei Jahreswechsel falsch, wenn man beispielsweise einen Wochentag berechnet:


Beispiel:

             Datum        Datumspattern
Eingabe      29122003     ddMMyyyy
                          wwyyyy

Erg:         01/2003

Richtig sollte aber sein 01/200_4_

	/**
	 * A date in a formated pattern will be convert in to a new date format.
	 * Example:
	 * 		date 08122005
	 * 		sourcePicture 	ddMMyyyy 	Java date pattern
	 *		targetPicture 	yyMMdd 		Java date pattern
	 *		result date 	051208
	 * Please refer to java.text.SimpleDateFormat for Date and Time Patterns
	 * @param date
	 *            incoming date, formated by source_picture
	 * @param source_picture
	 *            date format of the incoming date
	 * @param target_picture
	 *            in which date format will be the date converted
	 * @return the date formated to target_picture
	 */
	public static String convertDate(final String date,
										final String sourcePicture,
										final String targetPicture) {
		SimpleDateFormat *** = new SimpleDateFormat(sourcePicture);
		SimpleDateFormat tpic = new SimpleDateFormat(targetPicture);
		String ret = "";
		try {
			Date d = ***.parse(date);
			tpic.setLenient(true);
			ret = tpic.format(d);
		} catch (Exception e) {
			ret += "Error on converting date " + date + " from "
					+ sourcePicture + " to picture " + targetPicture + "\n";
			ret += "Error: " + e.getMessage() + "\n";
		}
		return ret;
	}
.