Ich versuche, Datum in benutzerdefiniertes Format zu konvertieren. Ich möchte ein Datum in allen Formaten haben. Aber formatierte Datum ist falsch bitte helfen.Datum in ein anderes Format umwandeln
package DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateFormat
{
DateFormat() throws ParseException
{
String dateFormats[] =
{
"YYYY/MM/DD",
"DD/MM/YYYY",
"DD-MM-YYYY",
};
for (int i = 0; i < dateFormats.length; i++)
{
String newDate = new SimpleDateFormat(dateFormats[i]).format(new Date());
System.out.println(newDate);
}
}
public static void main(String[] args) throws ParseException
{
new DateFormat();
}
}
Ausgang ist
2016/04/98
98/04/2016
98-04-2016
Danke.
Denn falsches Format. Informationen zu unterstützten Formaten finden Sie in der Dokumentation (http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html). – Rao